Skip to content

Commit

Permalink
Limit tag auto-close for td and th tags
Browse files Browse the repository at this point in the history
Fixes #1649
  • Loading branch information
bitwiseman committed Mar 25, 2019
1 parent 7487eb3 commit 1f7af59
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
4 changes: 2 additions & 2 deletions js/src/html/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,8 @@ Beautifier.prototype._do_optional_end_element = function(parser_token) {
} else if (parser_token.tag_name === 'th' || parser_token.tag_name === 'td') {
// A td element’s end tag may be omitted if the td element is immediately followed by a td or th element, or if there is no more content in the parent element.
// A th element’s end tag may be omitted if the th element is immediately followed by a td or th element, or if there is no more content in the parent element.
result = result || this._tag_stack.try_pop('td', ['tr']);
result = result || this._tag_stack.try_pop('th', ['tr']);
result = result || this._tag_stack.try_pop('td', ['table', 'thead', 'tbody', 'tfoot', 'tr']);
result = result || this._tag_stack.try_pop('th', ['table', 'thead', 'tbody', 'tfoot', 'tr']);
}

// Start element omission not handled currently
Expand Down
23 changes: 23 additions & 0 deletions js/test/generated/beautify-html-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6207,6 +6207,29 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
' <option>\n' +
' test content\n' +
'</select>');

// Regression test for #1649
bth(
'<table>\n' +
' <tbody>\n' +
' <tr>\n' +
' <td>\n' +
' <table>\n' +
' <thead>\n' +
' <th>\n' +
' </th>\n' +
' </thead>\n' +
' <tbody>\n' +
' <tr>\n' +
' <td>\n' +
' </td>\n' +
' </tr>\n' +
' </tbody>\n' +
' </table>\n' +
' </td>\n' +
' </tr>\n' +
' </tbody>\n' +
'</table>');
bth(
'<table>\n' +
' <caption>37547 TEE Electric Powered Rail Car Train Functions (Abbreviated)\n' +
Expand Down
24 changes: 24 additions & 0 deletions test/data/html/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,30 @@ exports.test_data = {
' test content',
'</select>'
]
}, {
comment: "Regression test for #1649",
unchanged: [
'<table>',
' <tbody>',
' <tr>',
' <td>',
' <table>',
' <thead>',
' <th>',
' </th>',
' </thead>',
' <tbody>',
' <tr>',
' <td>',
' </td>',
' </tr>',
' </tbody>',
' </table>',
' </td>',
' </tr>',
' </tbody>',
'</table>'
]
}, {
unchanged: [
'<table>',
Expand Down

0 comments on commit 1f7af59

Please sign in to comment.