Skip to content

Commit

Permalink
Removed treatment of html-comment as non-html
Browse files Browse the repository at this point in the history
This is a UI only change but added a test to guard the engine.

Fixed beautifier#1068
  • Loading branch information
bitwiseman committed Dec 18, 2016
1 parent 57738a4 commit 734f2ff
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
5 changes: 1 addition & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,8 @@

function looks_like_html(source) {
// <foo> - looks like html
// <!--\nalert('foo!');\n--> - doesn't look like html

var trimmed = source.replace(/^[ \t\n\r]+/, '');
var comment_mark = '<' + '!-' + '-';
return (trimmed && (trimmed.substring(0, 1) === '<' && trimmed.substring(0, 4) !== comment_mark));
return trimmed && (trimmed.substring(0, 1) === '<');
}
</script>
</head>
Expand Down
13 changes: 13 additions & 0 deletions js/test/generated/beautify-html-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,19 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
test_fragment('<div class="searchform"><input type="text" value="" name="s" id="s"><input type="submit" id="searchsubmit" value="Search"></div>');


//============================================================
// File starting with comment
reset_options();
test_fragment(
'<!--sample comment -->\n' +
'\n' +
'<html>\n' +
'<body>\n' +
' <span>a span</span>\n' +
'</body>\n' +
'</html>');


//============================================================
// Php formatting
reset_options();
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 @@ -711,6 +711,22 @@ exports.test_data = {
{ fragment: true, unchanged: '<div class="searchform"><input type="text" value="" name="s" id="s" /><input type="submit" id="searchsubmit" value="Search" /></div>' },
{ fragment: true, unchanged: '<div class="searchform"><input type="text" value="" name="s" id="s"><input type="submit" id="searchsubmit" value="Search"></div>' },
]
}, {
name: "File starting with comment",
description: "Unformatted tag behavior",
options: [],
tests: [{
fragment: true,
unchanged: [
'<!--sample comment -->',
'',
'<html>',
'<body>',
' <span>a span</span>',
'</body>',
'</html>'
]
}, ]
}, {
name: "Php formatting",
description: "Php (<?php ... ?>) treated as comments.",
Expand Down

0 comments on commit 734f2ff

Please sign in to comment.