Skip to content

Commit

Permalink
Ensure attribute selectors match tags that have new lines chars in at…
Browse files Browse the repository at this point in the history
…tr (#234)

Fixes #233
  • Loading branch information
facelessuser committed Nov 10, 2021
1 parent dad06a5 commit 8a53482
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs/src/markdown/about/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.3.1

- **FIX**: Ensure attribute selectors match tags that have new lines characters in attributes. (#233)

## 2.3

- **NEW**: Officially support Python 3.10.
Expand Down
2 changes: 1 addition & 1 deletion soupsieve/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,5 @@ def parse_version(ver: str) -> Version:
return Version(major, minor, micro, release, pre, post, dev)


__version_info__ = Version(2, 3, 0, "final")
__version_info__ = Version(2, 3, 1, "final")
__version__ = __version_info__._get_canonical()
6 changes: 3 additions & 3 deletions soupsieve/css_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,12 @@ def parse_attribute_selector(self, sel: _Selector, m: Match[str], has_selector:
value = ''

if case:
flags = re.I if case == 'i' else 0
flags = (re.I if case == 'i' else 0) | re.DOTALL
elif util.lower(attr) == 'type':
flags = re.I
flags = re.I | re.DOTALL
is_type = True
else:
flags = 0
flags = re.DOTALL

if op:
if m.group('value').startswith(('"', "'")):
Expand Down
50 changes: 50 additions & 0 deletions tests/test_level3/test_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,53 @@ def test_attribute_contains(self):
["0", "3", "pre"],
flags=util.HTML
)

def test_attribute_contains_with_newlines(self):
"""Test attribute `*=` will match with new lines."""

self.assert_selector(
"<p><span id='1' title='foo bar'>foo1</span><span id='2' title='foo\nbar'>foo1</span></p>",
"span[title*='bar']",
["1", "2"],
flags=util.HTML
)

def test_attribute_starts_with_newlines(self):
"""Test attribute `^=` will match with new lines."""

self.assert_selector(
"<p><span id='1' title='foo bar'>foo1</span><span id='2' title='foo\nbar'>foo1</span></p>",
"span[title^='foo']",
["1", "2"],
flags=util.HTML
)

def test_attribute_ends_with_newlines(self):
"""Test attribute `$=` will match with new lines."""

self.assert_selector(
"<p><span id='1' title='foo bar'>foo1</span><span id='2' title='foo\nbar'>foo1</span></p>",
"span[title$='bar']",
["1", "2"],
flags=util.HTML
)

def test_attribute_dash_list_with_newlines(self):
"""Test attribute `|=` will match with new lines."""

self.assert_selector(
"<p><span id='1' title='fo-o bar'>foo1</span><span id='2' title='fo-o\nbar'>foo1</span></p>",
"span[title|='fo']",
["1", "2"],
flags=util.HTML
)

def test_attribute_space_list_with_newlines(self):
"""Test attribute `~=` will match with new lines."""

self.assert_selector(
"<p><span id='1' title='foo bar baz'>foo1</span><span id='2' title='foo\nbar baz'>foo1</span></p>",
"span[title~='baz']",
["1", "2"],
flags=util.HTML
)

0 comments on commit 8a53482

Please sign in to comment.