Skip to content

Commit

Permalink
Fix #274
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 25, 2021
1 parent 2a262e0 commit bf3632c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,7 @@ Alex Heneveld (ahgittin@github)
for multi-line strings
(2.12.3)

James Wynn (jameswynn@github)
* Reported #274: YAMLGenerator does not quote tilde (~) characters when MINIMIZE_QUOTES
is enabled
(2.12.4)
6 changes: 6 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Modules:
=== Releases ===
------------------------------------------------------------------------

2.12.4 (not yet released)

#274: YAMLGenerator does not quote tilde (~) characters when MINIMIZE_QUOTES
is enabled
(reported by James W)

2.12.3 (12-Apr-2021)

#246: (yaml) Special characters shouldn't force double quoting for multi-line strings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ protected boolean _isReservedKeyword(int firstChar, String name) {
case 'T': // True
case 'Y': // Yes/Y
return RESERVED_KEYWORDS.contains(name);
case '~': // null alias (see [dataformats-text#274])
return true;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,21 @@ public void testMinimizeQuotesSpecialCharsMultiLine() throws Exception
assertEquals("---\n" +
"key: |-\n first\n second: third", yaml);
}

// [dataformats-text#274]: tilde is an alias for null values, must quote
// if written as String. Was already quoted by default but also must be quoted
// in minimized mode
public void testQuotingOfTilde() throws Exception
{
Map<String, Object> content = new HashMap<String, Object>();
content.put("key", "~");

assertEquals("---\n" +
"key: \"~\"",
VANILLA_MAPPER.writeValueAsString(content).trim());

assertEquals("---\n" +
"key: \"~\"",
MINIM_MAPPER.writeValueAsString(content).trim());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ public void testLiteralBlockStyle() throws Exception
"text: \"Hello World\"", yaml);
}

public void testSimpleNullProperty() throws Exception
{
StringWriter w = new StringWriter();
try (JsonGenerator gen = YAML_F.createGenerator(w)) {
gen.writeStartObject();
gen.writeFieldName("nullable");
gen.writeNull();
gen.writeEndObject();
}
// By default we'll get `null`, although tilde is a legal alternative
assertEquals("---\n" +
"nullable: null", w.toString().trim());
}

/*
/**********************************************************************
/* Helper methods
Expand Down

0 comments on commit bf3632c

Please sign in to comment.