Skip to content

Commit

Permalink
Correctly handle type attribute on non-script tags
Browse files Browse the repository at this point in the history
Fixes #1606
  • Loading branch information
bitwiseman committed Jan 8, 2019
1 parent b486524 commit 68f6494
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/src/html/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ var get_type_attribute = function(start_token) {
var raw_token = start_token.next;

// Search attributes for a type attribute
while (raw_token.type !== TOKEN.EOF && raw_token.closed !== start_token) {
while (raw_token.type !== TOKEN.EOF && start_token.closed !== raw_token) {
if (raw_token.type === TOKEN.ATTRIBUTE && raw_token.text === 'type') {
if (raw_token.next && raw_token.next.type === TOKEN.EQUALS &&
raw_token.next.next && raw_token.next.next.type === TOKEN.VALUE) {
Expand Down
14 changes: 14 additions & 0 deletions js/test/generated/beautify-html-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,20 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
'<script>\n' +
' var foo = "bar";\n' +
'</script>');

// Issue #1606 - type attribute on other element
bth(
'<script>\n' +
'console.log(1 + 1);\n' +
'</script>\n' +
'\n' +
'<input type="submit"></input>',
// -- output --
'<script>\n' +
' console.log(1 + 1);\n' +
'</script>\n' +
'\n' +
'<input type="submit"></input>');
bth(
'<script type="text/javascript">var foo = "bar";</script>',
// -- output --
Expand Down
16 changes: 16 additions & 0 deletions test/data/html/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,22 @@ exports.test_data = {
' var foo = "bar";',
'</script>'
]
}, {
comment: 'Issue #1606 - type attribute on other element',
input: [
'<script>',
'console.log(1 + 1);',
'</script>',
'',
'<input type="submit"></input>'
],
output: [
'<script>',
' console.log(1 + 1);',
'</script>',
'',
'<input type="submit"></input>'
]
}, {
input: '<script type="text/javascript">var foo = "bar";</script>',
output: [
Expand Down

0 comments on commit 68f6494

Please sign in to comment.