Skip to content

Commit

Permalink
Fix issue related to matching colors in buffer at a given offset
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser committed Apr 12, 2022
1 parent 1b5fb5c commit 02946c1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion coloraide/__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(0, 15, 0, "final", post=1)
__version_info__ = Version(0, 15, 1, "final")
__version__ = __version_info__._get_canonical()
3 changes: 2 additions & 1 deletion coloraide/css/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ def parse_css(
if value is not None:
return (value[:3], value[3]), m.end(0)
else:
return parse_rgb_channels(string[m.end(1) + 1:m.end(0) - 1], cspace.BOUNDS), m.end(0)
offset = m.start(0)
return parse_rgb_channels(string[m.end(1) - offset + 1:m.end(0) - offset - 1], cspace.BOUNDS), m.end(0)
else:
m = CSS_MATCH[cspace.NAME].match(string, start)
if m is not None and (not fullmatch or m.end(0) == len(string)):
Expand Down
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

## 0.15.1

- **FIX**: Fix an issue related to matching colors in a buffer at a given offset.

## 0.15.0

!!! warning
Expand Down
16 changes: 13 additions & 3 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,20 @@ def test_match_fullmatch(self):
def test_match_offset(self):
"""Test match with offset."""

obj = Color.match('yellow red', start=7)
self.assertEqual(obj.color, Color('red'))
obj = Color.match('yellow green #0000FF rgb(1, 0, 0)', start=7)
self.assertEqual(obj.color, Color('green'))
self.assertEqual(obj.start, 7)
self.assertEqual(obj.end, 10)
self.assertEqual(obj.end, 12)

obj = Color.match('yellow green #0000FF rgb(1, 0, 0)', start=13)
self.assertEqual(obj.color, Color('blue'))
self.assertEqual(obj.start, 13)
self.assertEqual(obj.end, 20)

obj = Color.match('yellow green #0000FF rgb(255, 0, 0)', start=21)
self.assertEqual(obj.color, Color('red'))
self.assertEqual(obj.start, 21)
self.assertEqual(obj.end, 35)

def test_match_filters(self):
"""Test match with filters."""
Expand Down

0 comments on commit 02946c1

Please sign in to comment.