Skip to content

Commit aaf133d

Browse files
committed
check HSL values for out of range (fixes ap#5)
1 parent d676ba4 commit aaf133d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

after/syntax/css.vim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function! s:FGForBG(color)
2020
endfunction
2121

2222
function! s:MatchColorValue(color, pattern)
23+
if ! len(a:color) | return | endif
2324
let group = 'cssColor' . tolower(a:color)
2425
let pattern = a:pattern
2526
if pattern =~ '\>$' | let pattern .= '\>' | endif
@@ -48,7 +49,7 @@ endfunction
4849

4950
function! s:HexForHSLValue(h,s,l)
5051
" Convert 80% -> 0.8, 100% -> 1.0, etc.
51-
let [s,l] = map( [a:s, a:l], 'v:val =~ "%$" ? v:val / 100.0 : v:val * 1.0' )
52+
let [s,l] = map( [a:s, a:l], 'v:val =~ "%$" ? v:val / 100.0 : str2float(v:val)' )
5253
" algorithm transcoded to vim from http://www.w3.org/TR/css3-color/#hsl-color
5354
let hh = ( a:h % 360 ) / 360.0
5455
let m2 = l <= 0.5 ? l * ( s + 1 ) : l + s - l * s
@@ -61,6 +62,7 @@ function! s:HexForHSLValue(h,s,l)
6162
\ h * 2 < 1 ? m2 :
6263
\ h * 3 < 2 ? m1 + ( m2 - m1 ) * ( 2/3.0 - h ) * 6 :
6364
\ m1
65+
if v > 1.0 | return '' | endif
6466
let rgb += [ float2nr( 255 * v ) ]
6567
endfor
6668
return printf( '%02x%02x%02x', rgb[0], rgb[1], rgb[2] )

0 commit comments

Comments
 (0)