Skip to content

Commit 40b7949

Browse files
fix bug: pick from extended set last
1 parent 2e8aaec commit 40b7949

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

JSONCrush.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,6 @@ function JSONCrush(string)
109109
// create a string of replacement characters
110110
let characters = [];
111111

112-
// pick from extended set last
113-
for (let i=255; i>32; --i)
114-
{
115-
let c = String.fromCharCode(i);
116-
if (c!='\\' && !characters.includes(c))
117-
characters.push(c);
118-
}
119-
120112
// prefer replacing with characters that will not be escaped by encodeURIComponent
121113
const unescapedCharacters = `-_.!~*'()`;
122114
for (let i=127; --i;)
@@ -130,6 +122,14 @@ function JSONCrush(string)
130122
)
131123
characters.push(String.fromCharCode(i));
132124
}
125+
126+
// pick from extended set last
127+
for (let i=32; i<255; ++i)
128+
{
129+
let c = String.fromCharCode(i);
130+
if (c!='\\' && !characters.includes(c))
131+
characters.unshift(c);
132+
}
133133

134134
// remove delimiter if it is found in the string
135135
string = string.replace(new RegExp(delimiter,'g'),'');

JSONCrush.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<br>
4343
<br>
4444
<br><div id=div_unit_test_results></div>
45-
<script src="JSONCrush.js?9"></script>
45+
<script src="JSONCrush.js?10"></script>
4646
<script>
4747

4848
"use strict"; // strict mode

0 commit comments

Comments
 (0)