Skip to content

Commit

Permalink
Fixed an infinite looping bug that arose when escape characters appea…
Browse files Browse the repository at this point in the history
…red in interpolated strings. There is still the limitation that you shouldn't use escapes for newlines, cr's, Unicode, etc. in your code sequences
  • Loading branch information
spencertipping committed May 29, 2010
1 parent b298974 commit 6304573
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion divergence.rebase.js
Expand Up @@ -198,7 +198,7 @@
// that build strings. Unfortunately we won't be able to distinguish between single and double-quoted strings because SpiderMonkey converts them all to double-quoted ones.

function (e) {return e.charAt && '\'"'.indexOf(e.charAt(0)) > -1 && /#\{[^}]+\}/.test(e) ?
'(' + e.replace (/#\{([^}]+)\}/g, function (_, code) {return e.charAt(0) + '+(' + r.translate(code) + ')+' + e.charAt(0)}) + ')' : e},
'(' + e.replace (/#\{([^}]+)\}/g, function (_, code) {return e.charAt(0) + '+(' + r.translate(code.replace(/\\(.)/g, '$1')) + ')+' + e.charAt(0)}) + ')' : e},

// Operator overloading.
// Once we're done with all of the preprocessing we can actually replace the operators with method calls. I'm cheating just a bit here; normally you would encase the operation inside a [ node
Expand Down
8 changes: 6 additions & 2 deletions divergence.rebase.test.js
Expand Up @@ -267,7 +267,7 @@ var d = (function () {
// that build strings. Unfortunately we won't be able to distinguish between single and double-quoted strings because SpiderMonkey converts them all to double-quoted ones.

function (e) {return e.charAt && '\'"'.indexOf(e.charAt(0)) > -1 && /#\{[^}]+\}/.test(e) ?
'(' + e.replace (/#\{([^}]+)\}/g, function (_, code) {return e.charAt(0) + '+(' + r.translate(code) + ')+' + e.charAt(0)}) + ')' : e},
'(' + e.replace (/#\{([^}]+)\}/g, function (_, code) {return e.charAt(0) + '+(' + r.translate(code.replace(/\\(.)/g, '$1')) + ')+' + e.charAt(0)}) + ')' : e},

// Operator overloading.
// Once we're done with all of the preprocessing we can actually replace the operators with method calls. I'm cheating just a bit here; normally you would encase the operation inside a [ node
Expand Down Expand Up @@ -519,7 +519,7 @@ var d = (function () {
// that build strings. Unfortunately we won't be able to distinguish between single and double-quoted strings because SpiderMonkey converts them all to double-quoted ones.

function (e) {return e.charAt && '\'"'.indexOf(e.charAt(0)) > -1 && /#\{[^}]+\}/.test(e) ?
'(' + e.replace (/#\{([^}]+)\}/g, function (_, code) {return e.charAt(0) + '+(' + r.translate(code) + ')+' + e.charAt(0)}) + ')' : e},
'(' + e.replace (/#\{([^}]+)\}/g, function (_, code) {return e.charAt(0) + '+(' + r.translate(code.replace(/\\(.)/g, '$1')) + ')+' + e.charAt(0)}) + ')' : e},

// Operator overloading.
// Once we're done with all of the preprocessing we can actually replace the operators with method calls. I'm cheating just a bit here; normally you would encase the operation inside a [ node
Expand Down Expand Up @@ -722,4 +722,8 @@ var d = (function () {

d.rebase (function () {
d.init ({}, {toString: _ >$> 'foo'});
}) ();

d.rebase (function () {
d.init ({}, {toString: _ >$> "foo#{3 + \"bar\"}"});
}) ();
14 changes: 9 additions & 5 deletions rebase
Expand Up @@ -284,7 +284,7 @@ var d = (function () {
__NIlSU01DmtXtQOiufJrifEZEqH1adWhSPDZLF5RACD0

meta::code('main', <<'__Iw1DFXCb9lg+s2/RisPHPChnOlJVs2eepM1wXrow8vA');
meta::code('main', <<'__k56TYzidJTVX63ITsHcNSwOasAqIoPz0nEDtbOmekuM');
Divergence Rebase module | Spencer Tipping <spencer@spencertipping.com>
Licensed under the terms of the MIT source code license
Expand Down Expand Up @@ -485,7 +485,7 @@ as a key there (e.g. 'foo'), then it will be sandwiched between binary operators
that build strings. Unfortunately we won't be able to distinguish between single and double-quoted strings because SpiderMonkey converts them all to double-quoted ones.
function (e) {return e.charAt && '\'"'.indexOf(e.charAt(0)) > -1 && /#\{[^}]+\}/.test(e) ?
'(' + e.replace (/#\{([^}]+)\}/g, function (_, code) {return e.charAt(0) + '+(' + r.translate(code) + ')+' + e.charAt(0)}) + ')' : e},
'(' + e.replace (/#\{([^}]+)\}/g, function (_, code) {return e.charAt(0) + '+(' + r.translate(code.replace(/\\(.)/g, '$1')) + ')+' + e.charAt(0)}) + ')' : e},
Operator overloading.
Once we're done with all of the preprocessing we can actually replace the operators with method calls. I'm cheating just a bit here; normally you would encase the operation inside a [ node
Expand Down Expand Up @@ -519,9 +519,9 @@ as a key there (e.g. 'foo'), then it will be sandwiched between binary operators
enable it like this:
r.enable_inline_macro = (function (enabled) {return function () {enabled || (enabled = !! d.inline_macros.push ('$0.toString()'.compose (r.transform).compose (r.parse)))}}) (false)}) ();
__Iw1DFXCb9lg+s2/RisPHPChnOlJVs2eepM1wXrow8vA
__k56TYzidJTVX63ITsHcNSwOasAqIoPz0nEDtbOmekuM

meta::code('test', <<'__M6nRCqxRlZGJS2N5v+qBH0mhHHc45Fhf8/HXozPPWBk');
meta::code('test', <<'__HrZA6wBcRrjN5lvZ19w1hPesA5M5ikLFvWHY4i0ipd4');
Divergence Rebase unit tests | Spencer Tipping <spencer@spencertipping.com>
Licensed under the terms of the MIT source code license
Expand Down Expand Up @@ -707,7 +707,11 @@ Parse tests.
d.rebase (function () {
d.init ({}, {toString: _ >$> 'foo'});
}) ();
__M6nRCqxRlZGJS2N5v+qBH0mhHHc45Fhf8/HXozPPWBk
d.rebase (function () {
d.init ({}, {toString: _ >$> "foo#{3 + \"bar\"}"});
}) ();
__HrZA6wBcRrjN5lvZ19w1hPesA5M5ikLFvWHY4i0ipd4

meta::code('test-utils', <<'__GQhahA9jt1+B2X1vxas2WOEFnHdUbgiwpAonT2s4VPs');
Unit test utilities.
Expand Down

0 comments on commit 6304573

Please sign in to comment.