Skip to content

Commit

Permalink
Fix #306 (quoting needed for field names with linefeeds)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 1, 2022
1 parent 416461a commit df08c1e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,6 @@ Falk Hanisch (mrpiggi@github)
for the same POJO
(2.13.1)

Esteban Ginez (eginez@github)
#306: (yaml) Error when generating/serializing keys with multilines and colon
(2.13.2)
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ No changes since 2.13

#303: (yaml) Update to SnakeYAML 1.30
(suggested by PJ Fanning)
#306: (yaml) Error when generating/serializing keys with multilines and colon
(reported by Esteban G)

2.13.1 (19-Dec-2021)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,27 @@ protected boolean valueHasQuotableChar(String inputStr)
}
return false;
}


/**
* Looks like we may get names with "funny characters" so.
*
* @since 2.13.2
*/
protected boolean nameHasQuotableChar(String inputStr)
{
// 31-Jan-2022, tatu: As per [dataformats-text#306] linefeed is
// problematic. I'm sure there are likely other cases, but let's
// start with the obvious ones, control characters
final int end = inputStr.length();
for (int i = 0; i < end; ++i) {
int ch = inputStr.charAt(i);
if (ch < 0x0020) {
return true;
}
}
return false;
}

/**
* Default {@link StringQuotingChecker} implementation used unless
* custom implementation registered.
Expand All @@ -189,7 +209,10 @@ public Default() { }
@Override
public boolean needToQuoteName(String name)
{
return isReservedKeyword(name) || looksLikeYAMLNumber(name);
return isReservedKeyword(name) || looksLikeYAMLNumber(name)
// 31-Jan-2022, tatu: as per [dataformats-text#306] may also
// have other characters requiring quoting...
|| nameHasQuotableChar(name);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.dataformat.yaml.failing;
package com.fasterxml.jackson.dataformat.yaml.deser;

import java.util.Collections;
import java.util.Map;
Expand Down

0 comments on commit df08c1e

Please sign in to comment.