facelessuser / ColorHelper

Sublime plugin that provides helpful color previews and tooltips
https://facelessuser.github.io/ColorHelper/
MIT License
256 stars 31 forks source link

Crash if css file has rgba(0, 0, 0, 0.1); #216

Closed ptcong closed 2 years ago

ptcong commented 2 years ago

Description

ValueError: could not convert string to float:

body {
    color:  rgba(0, 0, 0, 0.1);
}

Support Info

Steps to Reproduce Issue

  1. Create a .css file with above content
  2. See this issue
facelessuser commented 2 years ago

Interesting, it is not a problem with the underlying library:

Python 3.3>>> from ColorHelper.lib.coloraide import Color
Python 3.3>>> Color('rgba(0, 0, 0, 0.1)')
color(srgb 0 0 0 / 0.1)

So ColorHelper must be handing it something slightly malformed:

ColorHelper: ColorHelper: 
Traceback (most recent call last):
  File "/Users/facelessuser/Library/Application Support/Sublime Text/Packages/ColorHelper/ch_preview.py", line 538, in run
    self.do_search(force)
  File "/Users/facelessuser/Library/Application Support/Sublime Text/Packages/ColorHelper/ch_preview.py", line 397, in do_search
    obj = color_class.match(source, start=start, filters=filters)
  File "/Users/facelessuser/Library/Application Support/Sublime Text/Packages/ColorHelper/lib/coloraide/color.py", line 250, in match
    m = cls._match(string, start, fullmatch, filters=filters)
  File "/Users/facelessuser/Library/Application Support/Sublime Text/Packages/ColorHelper/lib/coloraide/color.py", line 233, in _match
    m2 = space_class.match(string, start, fullmatch)
  File "/Users/facelessuser/Library/Application Support/Sublime Text/Packages/ColorHelper/lib/coloraide/spaces/srgb/css.py", line 53, in match
    return parse.parse_css(cls, string, start, fullmatch)
  File "/Users/facelessuser/Library/Application Support/Sublime Text/Packages/ColorHelper/lib/coloraide/css/parse.py", line 345, in parse_css
    return parse_rgb_channels(string[m.end(1) + 1:m.end(0) - 1], cspace.BOUNDS), m.end(0)
  File "/Users/facelessuser/Library/Application Support/Sublime Text/Packages/ColorHelper/lib/coloraide/css/parse.py", line 256, in parse_rgb_channels
    channels.append(norm_rgb_channel(c, boundry[i].upper))
  File "/Users/facelessuser/Library/Application Support/Sublime Text/Packages/ColorHelper/lib/coloraide/css/parse.py", line 197, in norm_rgb_channel
    return norm_float(string) * RGB_CHANNEL_SCALE
  File "/Users/facelessuser/Library/Application Support/Sublime Text/Packages/ColorHelper/lib/coloraide/css/parse.py", line 160, in norm_float
    return float(string)
ValueError: could not convert string to float: 

Not sure what the issue is yet, but I'll see if I can figure out what is going on.

facelessuser commented 2 years ago

Okay, there actually is a problem in the lib, but only if you are giving it an index into a larger buffer to match a color. Apparently, this case for srgb was not exercised. I should have a fix out either today or tomorrow.

facelessuser commented 2 years ago

Related upstream bugfix: https://github.com/facelessuser/coloraide/pull/148

facelessuser commented 2 years ago

Fix has been released, though it could be 1 - 2 hours before it is seen in Package Control.

ptcong commented 2 years ago

Thank you, it's working fine now.