Last active
June 25, 2022 16:26
-
-
Save getify/3667624 to your computer and use it in GitHub Desktop.
Revisions
-
getify revised this gist
Dec 24, 2020 . 1 changed file with 9 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,15 +3,15 @@ function escapeDoubleQuotes(str) { return str.replace(/\\([\s\S])|(")/g,"\\$1$2"); // thanks @slevithan! } escapeDoubleQuotes(`ab`); // ab => ab (nothing escaped) escapeDoubleQuotes(`a"b`); // a"b => a\"b escapeDoubleQuotes(`a\\"b`); // a\"b => a\"b (nothing escaped) escapeDoubleQuotes(`a\\\\"b`); // a\\"b => a\\\"b escapeDoubleQuotes(`a\\\\\\"b`); // a\\\"b => a\\\"b (nothing escaped) escapeDoubleQuotes(`a"b"c`); // a"b"c => a\"b\"c escapeDoubleQuotes(`a""b`); // a""b => a\"\"b escapeDoubleQuotes(`""`); // "" => \"\" // don't unnecessarily escape: escapeDoubleQuotes(escapeDoubleQuotes(escapeDoubleQuotes(`a"b`))); // a"b => a\"b -
getify revised this gist
Sep 7, 2012 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,6 +10,8 @@ escapeDoubleQuotes("a\\\\\"b"); // a\\"b => a\\\"b escapeDoubleQuotes("a\\\\\\\"b"); // a\\\"b => a\\\"b escapeDoubleQuotes("a\"b\"c"); // a"b"c => a\"b\"c escapeDoubleQuotes("a\"\"b"); // a""b => a\"\"b escapeDoubleQuotes("\"\""); // "" => \"\" // don't unnecessarily escape: escapeDoubleQuotes(escapeDoubleQuotes(escapeDoubleQuotes("a\"b"))); // a"b => a\"b -
getify revised this gist
Sep 7, 2012 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ // NOTE: only escapes a " if it's not already escaped function escapeDoubleQuotes(str) { return str.replace(/\\([\s\S])|(")/g,"\\$1$2"); // thanks @slevithan! } escapeDoubleQuotes("ab"); // ab => ab @@ -9,5 +9,7 @@ escapeDoubleQuotes("a\\\"b"); // a\"b => a\"b escapeDoubleQuotes("a\\\\\"b"); // a\\"b => a\\\"b escapeDoubleQuotes("a\\\\\\\"b"); // a\\\"b => a\\\"b escapeDoubleQuotes("a\"b\"c"); // a"b"c => a\"b\"c // don't unnecessarily escape: escapeDoubleQuotes(escapeDoubleQuotes(escapeDoubleQuotes("a\"b"))); // a"b => a\"b -
getify revised this gist
Sep 7, 2012 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,5 +10,4 @@ escapeDoubleQuotes("a\\\\\"b"); // a\\"b => a\\\"b escapeDoubleQuotes("a\\\\\\\"b"); // a\\\"b => a\\\"b // don't unnecessarily escape: escapeDoubleQuotes(escapeDoubleQuotes(escapeDoubleQuotes("a\"b"))); // a"b => a\"b -
getify revised this gist
Sep 7, 2012 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,4 +7,8 @@ escapeDoubleQuotes("ab"); // ab => ab escapeDoubleQuotes("a\"b"); // a"b => a\"b escapeDoubleQuotes("a\\\"b"); // a\"b => a\"b escapeDoubleQuotes("a\\\\\"b"); // a\\"b => a\\\"b escapeDoubleQuotes("a\\\\\\\"b"); // a\\\"b => a\\\"b // don't unnecessarily escape: escapeDoubleQuotes(escapeDoubleQuotes(escapeDoubleQuotes("a\"b"))); // a"b => a\"b -
getify revised this gist
Sep 7, 2012 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ // NOTE: only escapes a " if it's not already escaped function escapeDoubleQuotes(str) { return str.replace(/(^|[^\\])((?:\\\\)*)\"/g,"$1$2\\\""); } -
getify revised this gist
Sep 7, 2012 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,8 +2,8 @@ function escapeDoubleQuotes(str) { return str.replace(/(^|[^\\])((?:\\\\)*)\"/g,"$1$2\\\""); } escapeDoubleQuotes("ab"); // ab => ab escapeDoubleQuotes("a\"b"); // a"b => a\"b escapeDoubleQuotes("a\\\"b"); // a\"b => a\"b escapeDoubleQuotes("a\\\\\"b"); // a\\"b => a\\\"b escapeDoubleQuotes("a\\\\\\\"b"); // a\\\"b => a\\\"b -
getify created this gist
Sep 7, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ function escapeDoubleQuotes(str) { return str.replace(/(^|[^\\])((?:\\\\)*)\"/g,"$1$2\\\""); } escapeDoubleQuotes("ab"); // ab escapeDoubleQuotes("a\"b"); // a\"b escapeDoubleQuotes("a\\\"b"); // a\"b escapeDoubleQuotes("a\\\\\"b"); // a\\\"b escapeDoubleQuotes("a\\\\\\\"b"); // a\\\"b