-
@wojtek The same error is in 8.1.0 so it may be good to consider backporting this fix for a next bugfix release.
-
According to the test case that you provided we could simplify
trimBodyToSize()
to:public static String trimBodyToSize(long limit, String body) { CharsetEncoder enc = StandardCharsets.UTF_8.newEncoder(); ByteBuffer bb = ByteBuffer.allocate((int) limit); CharBuffer cb = CharBuffer.wrap(body); CoderResult r = enc.encode(cb, bb, true); return r.isOverflow() ? cb.flip().toString() : body; }
But it seems you were not OK with it. The idea of having a unit test was to avoid erroneous "improvement". Please provide proper test that indicates what current solution is the only proper one (and above yields incorrect result)
Btw. I think
limit
parameter could be ofint
type here? -
I've added more tests to check chars with different code ranges from UTF8 specification and confirmed that your code works (in some cases even better). So I've replaced implementation and made a few changes, adjustments and comments, so I suppose that it is complete now.
Type |
Bug
|
Priority |
Normal
|
Assignee | |
Version |
tigase-server-8.2.0
|
Spent time |
0
|
Infinite loop while cutting body of encrypted push notification to fit the push notifications limit