Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dist/core/rules/attr-no-duplication.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions dist/core/rules/src-not-empty.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/core/rules/attr-no-duplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export default {

for (let i = 0, l = attrs.length; i < l; i++) {
attr = attrs[i]
attrName = attr.name
// HTML attribute names are ASCII case insensitive, so id and ID on the
// same element are a duplicate.
attrName = attr.name.toLowerCase()

if (mapAttrName[attrName] === true) {
reporter.error(
Expand Down
12 changes: 8 additions & 4 deletions src/core/rules/src-not-empty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ export default {
description: 'The src attribute of an img(script,link) must have a value.',
init(parser, reporter) {
parser.addListener('tagstart', (event) => {
const tagName = event.tagName
// HTML tag and attribute names are ASCII case insensitive, so compare
// against the lowercased form. The parser hands them over exactly as they
// were written.
const tagName = event.tagName.toLowerCase()
const attrs = event.attrs
let attr
const col = event.col + tagName.length + 1

for (let i = 0, l = attrs.length; i < l; i++) {
attr = attrs[i]
const attrName = attr.name.toLowerCase()

if (
((/^(img|script|embed|bgsound|iframe)$/.test(tagName) === true &&
attr.name === 'src') ||
(tagName === 'link' && attr.name === 'href') ||
(tagName === 'object' && attr.name === 'data')) &&
attrName === 'src') ||
(tagName === 'link' && attrName === 'href') ||
(tagName === 'object' && attrName === 'data')) &&
attr.value === ''
) {
reporter.error(
Expand Down
9 changes: 9 additions & 0 deletions test/rules/attr-no-duplication.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ describe(`Rules: ${ruleId}`, () => {
expect(messages[0].col).toBe(12)
})

it('Attribute name duplicated in a different case should result in an error', () => {
// HTML attribute names are ASCII case insensitive, so href and HREF on the
// same element are the same attribute.
const code = '<a href="a" HREF="b">bbb</a>'
const messages = HTMLHint.verify(code, ruleOptions)
expect(messages.length).toBe(1)
expect(messages[0].rule.id).toBe(ruleId)
})

it('Attribute name not been duplication should not result in an error', () => {
const code = '<a href="a">bbb</a>'
const messages = HTMLHint.verify(code, ruleOptions)
Expand Down
14 changes: 14 additions & 0 deletions test/rules/src-not-empty.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ describe(`Rules: ${ruleId}`, () => {
expect(messages.length).toBe(0)
})

it('Src be empty should result in an error whatever the case', () => {
// HTML tag and attribute names are ASCII case insensitive, so these are four
// spellings of one bug and all four have to be reported.
const code = '<img src="" /><img SRC="" /><IMG src="" /><IMG SRC="" />'
const messages = HTMLHint.verify(code, ruleOptions)
expect(messages.length).toBe(4)
})

it('Uppercase href and data should result in an error', () => {
const code = '<LINK HREF="" type="text/css" /><OBJECT DATA="">'
const messages = HTMLHint.verify(code, ruleOptions)
expect(messages.length).toBe(2)
})

it('Src be not set value should not result in an error', () => {
const code =
'<img width="200" /><script></script><link type="text/css" /><embed width="200"><bgsound /><iframe width="200"><object width="200">'
Expand Down
Loading