Correctly handle type attribute on non-script tags

Fixes #1606
This commit is contained in:
Liam Newman 2019-01-07 23:38:39 -08:00
parent b48652465a
commit 68f6494dd0
3 changed files with 31 additions and 1 deletions

View File

@ -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) {

View File

@ -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 --

View File

@ -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: [