Skip to content

Commit 2a72fe3

Browse files
committed
fix: Fix bug in JsonUrlTestAppender.addCodePoint()
1 parent 79936c9 commit 2a72fe3

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

module/jsonurl-core/src/main/java/org/jsonurl/text/JsonUrlTextAppender.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,11 @@ private static <T extends Appendable> void appendCodePoint(
384384
dest.append("%27");
385385

386386
} else {
387-
PercentCodec.encode(dest, codePoint, HEXENCODE_UNQUOTED, 0);
387+
PercentCodec.encode(
388+
dest,
389+
codePoint,
390+
optionAQF(options) ? HEXENCODE_AQF : HEXENCODE_UNQUOTED,
391+
0);
388392
}
389393
}
390394

module/jsonurl-core/src/test/java/org/jsonurl/text/JsonUrlStringBuilderTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,21 @@ void testAddCodePointEncoded(char codePoint) throws IOException {
151151
assertCodePoint(expected, codePoint);
152152
}
153153

154+
@ParameterizedTest
155+
@ValueSource(chars = {
156+
'+', '(', ')', ',', ':', '!'
157+
})
158+
void testAddCodePointEscaped(char codePoint) throws IOException {
159+
String actual = new JsonUrlStringBuilder(JsonUrlOption.AQF)
160+
.addCodePoint(codePoint)
161+
.build();
162+
163+
assertEquals(
164+
"!" + codePoint,
165+
actual,
166+
"addCodePoint(AQF," + codePoint + ") is escaped");
167+
}
168+
154169
@Test
155170
void testEmptyObject() throws IOException {
156171
final String testName = "empty object";

0 commit comments

Comments
 (0)