Skip to content

Commit ec32c89

Browse files
authored
Fix #373: escape positive numbers too if number quoting requested (#381)
1 parent 7cb6046 commit ec32c89

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

release-notes/VERSION-2.x

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ Active Maintainers:
1616

1717
2.15.0 (not yet released)
1818

19-
-
19+
#373: Positive numbers with plus sign not quoted correctly with
20+
`ALWAYS_QUOTE_NUMBERS_AS_STRINGS`
21+
(requested by @dyadyaJora)
2022

2123
2.14.2 (28-Jan-2023)
2224

yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/YAMLGenerator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private Feature(boolean defaultState) {
217217

218218
protected final static long MIN_INT_AS_LONG = (long) Integer.MIN_VALUE;
219219
protected final static long MAX_INT_AS_LONG = (long) Integer.MAX_VALUE;
220-
protected final static Pattern PLAIN_NUMBER_P = Pattern.compile("-?[0-9]*(\\.[0-9]*)?");
220+
protected final static Pattern PLAIN_NUMBER_P = Pattern.compile("[+-]?[0-9]*(\\.[0-9]*)?");
221221
protected final static String TAG_BINARY = Tag.BINARY.toString();
222222

223223
/*

yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorWithMinimizeTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ public void testLiteralStringsMultiLine() throws Exception
177177

178178
public void testQuoteNumberStoredAsString() throws Exception
179179
{
180+
// [dataformats-text#182]
181+
180182
YAMLFactory f = new YAMLFactory();
181183
// verify default settings
182184
assertFalse(f.isEnabled(YAMLGenerator.Feature.MINIMIZE_QUOTES));
@@ -206,6 +208,11 @@ public void testQuoteNumberStoredAsString() throws Exception
206208
yaml = mapper.writeValueAsString(Collections.singletonMap("key", "-60.25")).trim();
207209
assertEquals("---\n" +
208210
"key: \"-60.25\"", yaml);
211+
212+
// [dataformats-text#373]
213+
yaml = mapper.writeValueAsString(Collections.singletonMap("key", "+125")).trim();
214+
assertEquals("---\n" +
215+
"key: \"+125\"", yaml);
209216
}
210217

211218
public void testNonQuoteNumberStoredAsString() throws Exception

0 commit comments

Comments
 (0)