Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Fix for atom/language-xml#91 and atom/language-xml#96 #101

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
11 changes: 5 additions & 6 deletions grammars/xml.cson
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@
'captures':
'0':
'name': 'punctuation.definition.comment.xml'
'end': '--%>'
'name': 'comment.block.xml'
'end': '--%>'
'name': 'comment.block.xml'
}
{
'begin': '<!--'
Expand All @@ -418,10 +418,9 @@
'name': 'comment.block.xml'
'patterns': [
{
'begin': '--(?!>)'
'captures':
'0':
'name': 'invalid.illegal.bad-comments-or-CDATA.xml'
'begin': '(?=--(?!>))'
'end': '(?<!-)(?=-->)'
'name': 'invalid.illegal.bad-comments-or-CDATA.xml'
}
]
}
Expand Down
24 changes: 21 additions & 3 deletions spec/xml-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,36 @@ describe "XML grammar", ->
expect(lines[2][1]).toEqual value: '<!--', scopes: ['text.xml', 'meta.tag.sgml.doctype.xml', 'meta.internalsubset.xml', 'comment.block.xml', 'punctuation.definition.comment.xml']
expect(lines[3][1]).toEqual value: '<!--', scopes: ['text.xml', 'meta.tag.sgml.doctype.xml', 'meta.internalsubset.xml', 'comment.block.xml', 'punctuation.definition.comment.xml']

it 'tokenizes empty comment', ->
{tokens} = grammar.tokenizeLine('<!---->')
expect(tokens[0]).toEqual value: '<!--', scopes: ['text.xml', 'comment.block.xml', 'punctuation.definition.comment.xml']
expect(tokens[1]).toEqual value: '-->', scopes: ['text.xml', 'comment.block.xml', 'punctuation.definition.comment.xml']

it 'tokenizes comment endings with more than two dashes as invalid', ->
{tokens} = grammar.tokenizeLine('<!-- invalid comment --->')
expect(tokens[0]).toEqual value: '<!--', scopes: ['text.xml', 'comment.block.xml', 'punctuation.definition.comment.xml']
expect(tokens[1]).toEqual value: ' invalid comment ', scopes: ['text.xml', 'comment.block.xml']
expect(tokens[2]).toEqual value: '--', scopes: ['text.xml', 'comment.block.xml', 'invalid.illegal.bad-comments-or-CDATA.xml']
expect(tokens[2]).toEqual value: '--->', scopes: ['text.xml', 'comment.block.xml', 'invalid.illegal.bad-comments-or-CDATA.xml']

it 'tokenizes comments with two dashes not followed by ">" as invalid', ->
{tokens} = grammar.tokenizeLine('<!-- invalid -- comment -->')
expect(tokens[0]).toEqual value: '<!--', scopes: ['text.xml', 'comment.block.xml', 'punctuation.definition.comment.xml']
expect(tokens[1]).toEqual value: ' invalid ', scopes: ['text.xml', 'comment.block.xml']
expect(tokens[2]).toEqual value: '--', scopes: ['text.xml', 'comment.block.xml', 'invalid.illegal.bad-comments-or-CDATA.xml']
expect(tokens[3]).toEqual value: ' comment -->', scopes: ['text.xml', 'comment.block.xml']
expect(tokens[2]).toEqual value: '-- comment ', scopes: ['text.xml', 'comment.block.xml', 'invalid.illegal.bad-comments-or-CDATA.xml']
expect(tokens[3]).toEqual value: '-->', scopes: ['text.xml', 'comment.block.xml', 'punctuation.definition.comment.xml']

it 'tokenizes after invalid comment only if comment was properly closed', ->
{tokens} = grammar.tokenizeLine('<!-- invalid -- comment ---><n></n>--><n></n>')
expect(tokens[0]).toEqual value: '<!--', scopes: ['text.xml', 'comment.block.xml', 'punctuation.definition.comment.xml']
expect(tokens[1]).toEqual value: ' invalid ', scopes: ['text.xml', 'comment.block.xml']
expect(tokens[2]).toEqual value: '-- comment ---><n></n>', scopes: ['text.xml', 'comment.block.xml', 'invalid.illegal.bad-comments-or-CDATA.xml']
expect(tokens[3]).toEqual value: '-->', scopes: ['text.xml', 'comment.block.xml', 'punctuation.definition.comment.xml']
expect(tokens[4]).toEqual value: '<', scopes: ['text.xml', 'meta.tag.no-content.xml', 'punctuation.definition.tag.xml']
expect(tokens[5]).toEqual value: 'n', scopes: ['text.xml', 'meta.tag.no-content.xml', 'entity.name.tag.xml', 'entity.name.tag.localname.xml']
expect(tokens[6]).toEqual value: '>', scopes: ['text.xml', 'meta.tag.no-content.xml', 'punctuation.definition.tag.xml']
expect(tokens[7]).toEqual value: '</', scopes: ['text.xml', 'meta.tag.no-content.xml', 'punctuation.definition.tag.xml']
expect(tokens[8]).toEqual value: 'n', scopes: ['text.xml', 'meta.tag.no-content.xml', 'entity.name.tag.xml', 'entity.name.tag.localname.xml']
expect(tokens[9]).toEqual value: '>', scopes: ['text.xml', 'meta.tag.no-content.xml', 'punctuation.definition.tag.xml']

it "tokenizes empty element meta.tag.no-content.xml", ->
{tokens} = grammar.tokenizeLine('<n></n>')
Expand Down