Skip to content

Commit

Permalink
Correction to riot#1120
Browse files Browse the repository at this point in the history
  • Loading branch information
amarcruz committed Dec 2, 2015
1 parent 9053f28 commit b3e48e8
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion 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

Expand Down
8 changes: 6 additions & 2 deletions dist/compiler.js
Expand Up @@ -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
Expand Down Expand Up @@ -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]
}

Expand Down Expand Up @@ -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'), '')

Expand Down
8 changes: 6 additions & 2 deletions dist/riot.compiler.js
Expand Up @@ -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, '&quot;')
return _bp[0] + pcex[d]
})
}
return html
Expand Down Expand Up @@ -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]
}

Expand Down Expand Up @@ -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'), '')

Expand Down
2 changes: 1 addition & 1 deletion doc/guide.md
Expand Up @@ -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></p>', 'p { display: none; }', 'style=" top:0; left:0" expr="{{ foo:&quot;bar&quot; }}"', function(opts) {
riot.tag2('my-tag', '<p></p>', 'p { display: none; }', 'style=" top:0; left:0" expr="{{ foo:"bar" }}"', function(opts) {
this.click = function(e)
{}.bind(this)
}, '{ }');
Expand Down
4 changes: 3 additions & 1 deletion lib/core.js
Expand Up @@ -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'), '')

Expand Down
2 changes: 1 addition & 1 deletion test/specs/expect/whitespace.js
@@ -1,5 +1,5 @@
//src: test/specs/fixtures/whitespace.tag
riot.tag2('my-tag', '<p></p>', 'p { display: none; }', 'style=" top:0; left:0" expr="{{ foo:&quot;bar&quot; }}"', function(opts) {
riot.tag2('my-tag', '<p></p>', 'p { display: none; }', 'style=" top:0; left:0" expr="{{ foo:"bar" }}"', function(opts) {
this.click = function(e)
{}.bind(this)
}, '{ }');
8 changes: 4 additions & 4 deletions test/specs/html.js
Expand Up @@ -69,10 +69,10 @@ describe('Compile HTML', function() {
})

it('double quotes in expressions are converted to `&quot;`', function () {
testStr('<p x={ "a" } y="{2}">', '<p x="{&quot;a&quot;}" y="{2}">')
testStr('<p x="{"a"}" y="{2}">', '<p x="{&quot;a&quot;}" y="{2}">')
testStr('<p x=\'{"a"}\' y="{2}">', '<p x="{&quot;a&quot;}" y="{2}">')
testStr('<p x="{""}">', '<p x="{&quot;&quot;}">')
testStr('<p x={ "a" } y="{2}">', '<p x="{"a"}" y="{2}">')
testStr('<p x="{"a"}" y="{2}">', '<p x="{"a"}" y="{2}">')
testStr('<p x=\'{"a"}\' y="{2}">', '<p x="{"a"}" y="{2}">')
testStr('<p x="{""}">', '<p x="{""}">')
})

it('single quotes in expressions are escaped', function () {
Expand Down
4 changes: 2 additions & 2 deletions test/specs/parsers/suite.js
Expand Up @@ -71,8 +71,8 @@ describe('HTML parsers', function () {
})

it('plays with quoted values', function () {
testStr('<a href={ "a" }>', '<a href="{@ &quot;a&quot;}">', opts)
testStr('<a>{"b"}</a>', '<a>{@&quot;b&quot;}</a>', opts)
testStr('<a href={ "a" }>', '<a href="{@ "a"}">', opts)
testStr('<a>{"b"}</a>', '<a>{@"b"}</a>', opts)
})

it('remove the last semi-colon', function () {
Expand Down

0 comments on commit b3e48e8

Please sign in to comment.