Skip to content

Commit

Permalink
Support parsing attributes which contain uppercase letters
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudcolas committed Mar 30, 2020
1 parent 712ab64 commit fdd9554
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Changed

- Open `attrs` dependency from `attrs==17.2.0` to `attrs>=17.2.0`.
- Support parsing attributes with uppercase letters (e.g. `viewBox`).

## [v0.5.0](https://github.com/thibaudcolas/curlylint/releases/tag/v0.5.0) 2020-03-24

Expand Down
7 changes: 6 additions & 1 deletion curlylint/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,17 @@ def make_attribute_value_parser(jinja):
).desc("attribute value")


attr_name_start_char = P.regex(r"[:a-zA-Z]")
attr_name_char = attr_name_start_char | P.regex(r"[0-9A-Z-_.]")
attr_name = attr_name_start_char + attr_name_char.many().concat()


def make_attribute_parser(jinja):
attribute_value = make_attribute_value_parser(jinja)
return (
locate(
P.seq(
interpolated(tag_name),
interpolated(attr_name),
whitespace.then(
P.seq(
P.string("=").skip(whitespace).tag("equal"),
Expand Down
9 changes: 9 additions & 0 deletions curlylint/parse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ def test_attribute():
name=Interp("a"), value=Interp(String(value=Interp("b"), quote='"'))
)

assert attribute.parse('A="b"') == Attribute(
name=Interp("A"), value=Interp(String(value=Interp("b"), quote='"'))
)

assert attribute.parse('viewBox="b"') == Attribute(
name=Interp("viewBox"),
value=Interp(String(value=Interp("b"), quote='"')),
)

assert attribute.parse("a =b_c23") == Attribute(
name=Interp("a"),
value=Interp(String(value=Interp("b_c23"), quote=None)),
Expand Down

0 comments on commit fdd9554

Please sign in to comment.