Skip to content

Commit

Permalink
Add more descriptive error message for missing whitespace between HTM…
Browse files Browse the repository at this point in the history
…L attributes

#23 (comment)
  • Loading branch information
thibaudcolas committed Mar 13, 2021
1 parent 84fb394 commit 7528651
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
## Unreleased

### Changed

- Add more descriptive error message for missing whitespace between HTML attributes ([#23 (comment)](https://github.com/thibaudcolas/curlylint/issues/23#issuecomment-700622837))

## [v0.12.2](https://github.com/thibaudcolas/curlylint/releases/tag/v0.12.2) 2021-03-06

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion curlylint/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
# XXX: It could be better and simpler to only allow ASCII whitespaces here.
whitespace = P.regex(r"\s*")
mandatory_whitespace = P.regex(r"\s+")
spaces_between_attr = mandatory_whitespace.desc("space(s) between attributes")


def until(parser):
Expand Down Expand Up @@ -415,7 +416,7 @@ def make_attributes_parser(config, jinja):

attrs = interpolated(
(
whitespace.then(jinja_attr) | mandatory_whitespace.then(attribute)
whitespace.then(jinja_attr) | spaces_between_attr.then(attribute)
).many()
)

Expand Down
12 changes: 12 additions & 0 deletions curlylint/parse_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import pytest

import parsy as P

Expand Down Expand Up @@ -221,6 +222,17 @@ def test_opening_tag(self):
),
)

def test_opening_tag_attributes_no_space(self):
# See https://html.spec.whatwg.org/multipage/syntax.html#start-tags
# "Attributes must be separated from each other by one or more ASCII whitespace."
# See https://github.com/thibaudcolas/curlylint/issues/23#issuecomment-700622837
with pytest.raises(
P.ParseError, match="space\\(s\\) between attributes",
):
opening_tag.parse(
'<a class="govuk-button"href="/cookies">Set cookie preferences</a>'
)


def test_closing_tag():
closing_tag = make_closing_tag_parser(P.string("div"))
Expand Down

0 comments on commit 7528651

Please sign in to comment.