Skip to content

Commit

Permalink
Escape control chars in keys (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
trobro authored Oct 23, 2023
1 parent 85205fb commit 60737ac
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion assets/charset2_result.hjson
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
uescape: "\u0000,\u0001,\uffff"
umlaut: äöüßÄÖÜ
"um\u000blaut": äöüßÄÖÜ
hex: ģ䕧覫췯ꯍ
}
2 changes: 1 addition & 1 deletion assets/charset2_result.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"uescape": "\u0000,\u0001,￿",
"umlaut": "äöüßÄÖÜ",
"um\u000blaut": "äöüßÄÖÜ",
"hex": "ģ䕧覫췯ꯍ"
}
2 changes: 1 addition & 1 deletion assets/charset2_test.hjson
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
uescape: "\u0000,\u0001,\uffff"
umlaut: äöüßÄÖÜ
"um\u000blaut": äöüßÄÖÜ
hex: "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A"
}
2 changes: 1 addition & 1 deletion assets/comments2/charset2_result.hjson
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
uescape: "\u0000,\u0001,\uffff"
umlaut: äöüßÄÖÜ
"um\u000blaut": äöüßÄÖÜ
hex: ģ䕧覫췯ꯍ
}
2 changes: 1 addition & 1 deletion assets/comments3/charset2_result.hjson
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
uescape: "\u0000,\u0001,\uffff"
umlaut: äöüßÄÖÜ
"um\u000blaut": äöüßÄÖÜ
hex: ģ䕧覫췯ꯍ
}
2 changes: 1 addition & 1 deletion assets/sorted/charset2_result.hjson
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
hex: ģ䕧覫췯ꯍ
uescape: "\u0000,\u0001,\uffff"
umlaut: äöüßÄÖÜ
"um\u000blaut": äöüßÄÖÜ
}
2 changes: 1 addition & 1 deletion assets/sorted/charset2_result.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"hex": "ģ䕧覫췯ꯍ",
"uescape": "\u0000,\u0001,￿",
"umlaut": "äöüßÄÖÜ"
"um\u000blaut": "äöüßÄÖÜ"
}
7 changes: 2 additions & 5 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,8 @@ func (e *hjsonEncoder) quoteName(name string) string {

// Check if we can insert this name without quotes

if needsEscapeName.MatchString(name) {
if needsEscape.MatchString(name) {
name = e.quoteReplace(name)
}
return `"` + name + `"`
if needsEscapeName.MatchString(name) || needsEscape.MatchString(name) {
return `"` + e.quoteReplace(name) + `"`
}
// without quotes
return name
Expand Down

0 comments on commit 60737ac

Please sign in to comment.