diff --git a/coloraide/__meta__.py b/coloraide/__meta__.py index 5b3faff8f..b434393ff 100644 --- a/coloraide/__meta__.py +++ b/coloraide/__meta__.py @@ -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() diff --git a/coloraide/css/parse.py b/coloraide/css/parse.py index 9584b7a96..efc8a1f5b 100644 --- a/coloraide/css/parse.py +++ b/coloraide/css/parse.py @@ -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)): diff --git a/docs/src/markdown/about/changelog.md b/docs/src/markdown/about/changelog.md index c737d4ddf..564afed0f 100644 --- a/docs/src/markdown/about/changelog.md +++ b/docs/src/markdown/about/changelog.md @@ -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 diff --git a/tests/test_api.py b/tests/test_api.py index cda7e35d9..c1a0ab7f6 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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."""