Skip to content

Commit

Permalink
Fix #373: escape positive numbers too if number quoting requested
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 10, 2023
1 parent 7cb6046 commit 501bad0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Active Maintainers:

2.15.0 (not yet released)

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

2.14.2 (28-Jan-2023)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private Feature(boolean defaultState) {

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

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ public void testLiteralStringsMultiLine() throws Exception

public void testQuoteNumberStoredAsString() throws Exception
{
// [dataformats-text#182]

YAMLFactory f = new YAMLFactory();
// verify default settings
assertFalse(f.isEnabled(YAMLGenerator.Feature.MINIMIZE_QUOTES));
Expand Down Expand Up @@ -206,6 +208,11 @@ public void testQuoteNumberStoredAsString() throws Exception
yaml = mapper.writeValueAsString(Collections.singletonMap("key", "-60.25")).trim();
assertEquals("---\n" +
"key: \"-60.25\"", yaml);

// [dataformats-text#373]
yaml = mapper.writeValueAsString(Collections.singletonMap("key", "+125")).trim();
assertEquals("---\n" +
"key: \"+125\"", yaml);
}

public void testNonQuoteNumberStoredAsString() throws Exception
Expand Down

0 comments on commit 501bad0

Please sign in to comment.