Skip to content

Commit

Permalink
fix bug: pick from extended set last
Browse files Browse the repository at this point in the history
  • Loading branch information
KilledByAPixel committed Dec 10, 2019
1 parent 2e8aaec commit 40b7949
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions JSONCrush.js
Expand Up @@ -109,14 +109,6 @@ function JSONCrush(string)
// create a string of replacement characters
let characters = [];

// pick from extended set last
for (let i=255; i>32; --i)
{
let c = String.fromCharCode(i);
if (c!='\\' && !characters.includes(c))
characters.push(c);
}

// prefer replacing with characters that will not be escaped by encodeURIComponent
const unescapedCharacters = `-_.!~*'()`;
for (let i=127; --i;)
Expand All @@ -130,6 +122,14 @@ function JSONCrush(string)
)
characters.push(String.fromCharCode(i));
}

// pick from extended set last
for (let i=32; i<255; ++i)
{
let c = String.fromCharCode(i);
if (c!='\\' && !characters.includes(c))
characters.unshift(c);
}

// remove delimiter if it is found in the string
string = string.replace(new RegExp(delimiter,'g'),'');
Expand Down
2 changes: 1 addition & 1 deletion JSONCrush.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -42,7 +42,7 @@
<br>
<br>
<br><div id=div_unit_test_results></div>
<script src="JSONCrush.js?9"></script>
<script src="JSONCrush.js?10"></script>
<script>

"use strict"; // strict mode
Expand Down

0 comments on commit 40b7949

Please sign in to comment.