Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ImportedProjects
SVG
Commits
9fc47d84
Commit
9fc47d84
authored
Feb 21, 2019
by
mrbean-bremen
Committed by
mrbean-bremen
Feb 22, 2019
Browse files
Added handling of invalid color as default color
- adapted test to check for default value - see #399
parent
326dae7c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Source/External/ExCSS/Parser.Blocks.cs
View file @
9fc47d84
...
...
@@ -554,10 +554,13 @@ namespace Svg.ExCSS
{
HtmlColor
htmlColor
;
if
(
HtmlColor
.
TryFromHex
(
color
,
out
htmlColor
))
if
(
HtmlColor
.
TryFromHex
(
color
,
out
htmlColor
))
return
AddTerm
(
htmlColor
);
return
false
;
else
// the value is invalid - remove the property to use the default value
RemoveCurrentProperty
();
return
true
;
}
#
region
Namespace
...
...
Tests/Svg.UnitTests/LexerIssueTests.cs
View file @
9fc47d84
...
...
@@ -62,8 +62,29 @@ namespace Svg.UnitTests
[
TestMethod
]
public
void
Lexer_FileWithInvalidHex_ColorTagIsIgnored
()
{
Assert
.
Inconclusive
(
"This test fails due to a lexer error"
);
GenerateLexerTestFile
(
"color: #0046;"
);
// valid colors
var
doc
=
GenerateLexerTestFile
(
"fill: #ff0000; stroke: #ffff00"
);
var
path
=
doc
.
GetElementById
<
SvgPath
>(
"path1"
);
Assert
.
AreEqual
(
System
.
Drawing
.
Color
.
Red
,
((
SvgColourServer
)
path
.
Fill
).
Colour
);
Assert
.
AreEqual
(
System
.
Drawing
.
Color
.
Yellow
,
((
SvgColourServer
)
path
.
Stroke
).
Colour
);
// invalid/valid color combinations - default color is used for each invalid color
doc
=
GenerateLexerTestFile
(
"fill: #ff00; stroke: #00ff00"
);
path
=
doc
.
GetElementById
<
SvgPath
>(
"path1"
);
// default fill color is Black
Assert
.
AreEqual
(
System
.
Drawing
.
Color
.
Black
,
((
SvgColourServer
)
path
.
Fill
).
Colour
);
Assert
.
AreEqual
(
System
.
Drawing
.
Color
.
Lime
,
((
SvgColourServer
)
path
.
Stroke
).
Colour
);
doc
=
GenerateLexerTestFile
(
"fill: #fff; stroke: 005577"
);
path
=
doc
.
GetElementById
<
SvgPath
>(
"path1"
);
Assert
.
AreEqual
(
System
.
Drawing
.
Color
.
White
,
((
SvgColourServer
)
path
.
Fill
).
Colour
);
// default stroke color is null (transparent)
Assert
.
IsNull
(
path
.
Stroke
);
doc
=
GenerateLexerTestFile
(
"fill:; stroke: #00557;"
);
path
=
doc
.
GetElementById
<
SvgPath
>(
"path1"
);
Assert
.
AreEqual
(
System
.
Drawing
.
Color
.
Black
,
((
SvgColourServer
)
path
.
Fill
).
Colour
);
Assert
.
IsNull
(
path
.
Stroke
);
}
/// <summary>
...
...
Tests/Svg.UnitTests/Resources/Issue399_LexerIssue/LexerTestTemplate.svg
View file @
9fc47d84
<svg
xmlns=
"http://www.w3.org/2000/svg"
width=
"1092"
height=
"453"
>
<style
type=
"text/css"
>
#footer
{
/*[REPLACE]*/
}
</style>
.plot-zero {
/*[REPLACE]*/
}
</style>
<g
transform=
"translate(40,20)"
style=
"opacity: 1;"
>
<path
class=
"plot-zero"
d=
"M0,0 H1042"
style=
"opacity: 0;"
></path>
<path
class=
"plot-zero"
id=
"path1"
d=
"M0,0 H1042"
></path>
<path
class=
"plot-now"
d=
""
style=
"opacity: 0;"
></path>
</g>
<clipPath
id=
"clip-view-2"
>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment