From aac19da12ce409d6c1fe89de4441efcf5e72a841 Mon Sep 17 00:00:00 2001 From: VittGam Date: Mon, 25 Jun 2012 00:09:14 +0200 Subject: [PATCH] Fixed unescape_strings bug introduced along \uNNNN unescaping. --- beautify.js | 2 +- php/jsbeautifier.php | 4 ++-- python/jsbeautifier/__init__.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/beautify.js b/beautify.js index 157692d7..c4955d25 100755 --- a/beautify.js +++ b/beautify.js @@ -531,7 +531,7 @@ function js_beautify(js_source_text, options) { // while (esc || input.charAt(parser_pos) !== sep) { resulting_string += input.charAt(parser_pos); - if (esc1 >= esc2) { + if (esc1 && esc1 >= esc2) { esc1 = parseInt(resulting_string.substr(-esc2), 16); if (esc1 && esc1 >= 0x20 && esc1 <= 0x7e) { esc1 = String.fromCharCode(esc1); diff --git a/php/jsbeautifier.php b/php/jsbeautifier.php index 189d7658..1b8855c9 100644 --- a/php/jsbeautifier.php +++ b/php/jsbeautifier.php @@ -629,11 +629,11 @@ class JSBeautifier while ($esc || $this->input[$this->parser_pos] != $sep) { $resulting_string .= $this->input[$this->parser_pos]; - if ($esc1 >= $esc2) { + if ($esc1 && $esc1 >= $esc2) { $esc1 = hexdec(substr($resulting_string, -$esc2)); if ($esc1 && $esc1 >= 0x20 && $esc1 <= 0x7e) { $esc1 = chr($esc1); - $resulting_string = substr($resulting_string, 0, -($esc2 + 2)) . ((($esc1 === $sep) || ($esc1 === '\\')) ? '\\' : '') . $esc1; + $resulting_string = substr($resulting_string, 0, -2 - $esc2) . ((($esc1 === $sep) || ($esc1 === '\\')) ? '\\' : '') . $esc1; } $esc1 = 0; } diff --git a/python/jsbeautifier/__init__.py b/python/jsbeautifier/__init__.py index bfa2d344..1d3b825e 100644 --- a/python/jsbeautifier/__init__.py +++ b/python/jsbeautifier/__init__.py @@ -557,7 +557,7 @@ class Beautifier: # handle string while esc or self.input[parser_pos] != sep: resulting_string += self.input[parser_pos] - if esc1 >= esc2: + if esc1 and esc1 >= esc2: try: esc1 = int(resulting_string[-esc2:], 16) except Exception: