Skip to content

Commit 7ac8b28

Browse files
authored
Merge pull request #7 from 5225225/fix-parse-error
Fix error when parsing hex value with non-ASCII
2 parents a0e0671 + bca33b5 commit 7ac8b28

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/parser/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ pub fn parse(s: &str) -> Result<Color, ParseColorError> {
255255
}
256256

257257
fn parse_hex(s: &str) -> Result<Color, Box<dyn error::Error>> {
258+
if !s.is_ascii() {
259+
return Err(Box::new(ParseColorError::InvalidHex));
260+
}
261+
258262
let n = s.len();
259263

260264
let (r, g, b, a) = if n == 3 || n == 4 {

tests/parser.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn lime_alpha() {
195195
}
196196
}
197197

198-
#[cfg(all(feature = "named-colors", features = "lab"))]
198+
#[cfg(all(feature = "named-colors", feature = "lab"))]
199199
#[test]
200200
fn invalid_format() {
201201
let test_data = vec![
@@ -240,6 +240,10 @@ fn invalid_format() {
240240
("cmyk(0,0,0,0)", "Invalid color function."),
241241
("blood", "Invalid unknown format."),
242242
("rgb(255,0,0", "Invalid unknown format."),
243+
("x£", "Invalid unknown format."),
244+
("x£x", "Invalid unknown format."),
245+
("xxx£x", "Invalid unknown format."),
246+
("xxxxx£x", "Invalid unknown format."),
243247
];
244248

245249
for (s, err_msg) in test_data {

0 commit comments

Comments
 (0)