From b3e48e884c8131b9259a1f16f1c89287a5fc571b Mon Sep 17 00:00:00 2001 From: amarcruz Date: Wed, 2 Dec 2015 12:03:45 -0600 Subject: [PATCH] Correction to riot#1120 --- CHANGELOG.md | 2 +- dist/compiler.js | 8 ++++++-- dist/riot.compiler.js | 8 ++++++-- doc/guide.md | 2 +- lib/core.js | 4 +++- test/specs/expect/whitespace.js | 2 +- test/specs/html.js | 8 ++++---- test/specs/parsers/suite.js | 4 ++-- 8 files changed, 24 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b1cb05..b4b3f7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Compiler Changes ## v2.3.15 -- Regression for fix [riot#1120](https://github.com/riot/riot/issues/1120), browsers behavior is inconsistent, `tmpl` can parse double-quotes within expressions. +- Correction for fix [riot#1120](https://github.com/riot/riot/issues/1120), `tmpl` can parse double-quotes within expressions, encoding the quotes generates issues. ## v2.3.14 diff --git a/dist/compiler.js b/dist/compiler.js index b32b613..3f9d361 100644 --- a/dist/compiler.js +++ b/dist/compiler.js @@ -275,7 +275,7 @@ if (pcex.length) { html = html .replace(/\u0001(\d+)/g, function (_, d) { - return _bp[0] + pcex[d].replace(/"/g, '"') + return _bp[0] + pcex[d] }) } return html @@ -496,6 +496,8 @@ k = str.lastIndexOf('<', k -1) } + // TODO 2.4.0 make untagged content html, update the guide too + //return [str, ''] // no closing tag found, assume html text return ['', str] } @@ -559,8 +561,10 @@ if (body && (body = body.replace(HTML_COMMENT, '')) && /\S/.test(body)) { - if (body2) + if (body2) { + /* istanbul ignore next */ html = included('html') ? compileHTML(body2, opts, pcex, 1) : '' + } else { body = body.replace(_regEx('^' + indent, 'gm'), '') diff --git a/dist/riot.compiler.js b/dist/riot.compiler.js index e4b94d5..cf95500 100644 --- a/dist/riot.compiler.js +++ b/dist/riot.compiler.js @@ -206,7 +206,7 @@ var compile = (function () { if (pcex.length) { html = html .replace(/\u0001(\d+)/g, function (_, d) { - return _bp[0] + pcex[d].replace(/"/g, '"') + return _bp[0] + pcex[d] }) } return html @@ -427,6 +427,8 @@ var compile = (function () { k = str.lastIndexOf('<', k -1) } + // TODO 2.4.0 make untagged content html, update the guide too + //return [str, ''] // no closing tag found, assume html text return ['', str] } @@ -487,8 +489,10 @@ var compile = (function () { if (body && (body = body.replace(HTML_COMMENT, '')) && /\S/.test(body)) { - if (body2) + if (body2) { + /* istanbul ignore next */ html = included('html') ? compileHTML(body2, opts, pcex, 1) : '' + } else { body = body.replace(_regEx('^' + indent, 'gm'), '') diff --git a/doc/guide.md b/doc/guide.md index faa44b7..1f76aa7 100644 --- a/doc/guide.md +++ b/doc/guide.md @@ -106,7 +106,7 @@ This example shows the behavior with the default options on different parts of a will generate this: ```js -riot.tag2('my-tag', '

', 'p { display: none; }', 'style=" top:0; left:0" expr="{{ foo:"bar" }}"', function(opts) { +riot.tag2('my-tag', '

', 'p { display: none; }', 'style=" top:0; left:0" expr="{{ foo:"bar" }}"', function(opts) { this.click = function(e) {}.bind(this) }, '{ }'); diff --git a/lib/core.js b/lib/core.js index 9300828..c9bf01f 100644 --- a/lib/core.js +++ b/lib/core.js @@ -567,8 +567,10 @@ var compile = (function () { // remove comments and trim trailing whitespace if (body && (body = body.replace(HTML_COMMENT, '')) && /\S/.test(body)) { - if (body2) + if (body2) { + /* istanbul ignore next */ html = included('html') ? compileHTML(body2, opts, pcex, 1) : '' + } else { body = body.replace(_regEx('^' + indent, 'gm'), '') diff --git a/test/specs/expect/whitespace.js b/test/specs/expect/whitespace.js index e454f88..6cf91df 100644 --- a/test/specs/expect/whitespace.js +++ b/test/specs/expect/whitespace.js @@ -1,5 +1,5 @@ //src: test/specs/fixtures/whitespace.tag -riot.tag2('my-tag', '

', 'p { display: none; }', 'style=" top:0; left:0" expr="{{ foo:"bar" }}"', function(opts) { +riot.tag2('my-tag', '

', 'p { display: none; }', 'style=" top:0; left:0" expr="{{ foo:"bar" }}"', function(opts) { this.click = function(e) {}.bind(this) }, '{ }'); diff --git a/test/specs/html.js b/test/specs/html.js index d028be4..309e376 100644 --- a/test/specs/html.js +++ b/test/specs/html.js @@ -69,10 +69,10 @@ describe('Compile HTML', function() { }) it('double quotes in expressions are converted to `"`', function () { - testStr('

', '

') - testStr('

', '

') - testStr('

', '

') - testStr('

', '

') + testStr('

', '

') + testStr('

', '

') + testStr('

', '

') + testStr('

', '

') }) it('single quotes in expressions are escaped', function () { diff --git a/test/specs/parsers/suite.js b/test/specs/parsers/suite.js index 28e8acd..8127cd8 100644 --- a/test/specs/parsers/suite.js +++ b/test/specs/parsers/suite.js @@ -71,8 +71,8 @@ describe('HTML parsers', function () { }) it('plays with quoted values', function () { - testStr('', '', opts) - testStr('{"b"}', '{@"b"}', opts) + testStr('', '', opts) + testStr('{"b"}', '{@"b"}', opts) }) it('remove the last semi-colon', function () {