-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[vector_graphics_compiler] fix: handle parsing stroke-width with an invalid value #8004
Changes from 16 commits
878304b
a14a296
27c5129
d23b800
75aba47
8d754b7
94f6168
71830ee
6fbe33b
7cd5021
4aa435c
5783843
a69d531
e103432
724c7b9
49a8855
66d11b4
8a1440f
7674b9b
141c99a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 1.1.16 | ||
|
||
* Fixes an issue when parsing stroke-width with an invalid value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is missing a period; please see the CHANGELOG style guide linked from the checklist. |
||
|
||
## 1.1.15 | ||
|
||
* Fixes a bug where empty tags caused the parser to crash. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -704,6 +704,85 @@ void main() { | |
]); | ||
}); | ||
|
||
test('stroke-width with invalid value', () { | ||
const String svg = | ||
'<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><path d="M100 10 H180 V90 H100 Z" fill="#ff0000" stroke="#0000ff" stroke-width="invalid"/></svg>'; | ||
|
||
final VectorInstructions instructions = parseWithoutOptimizers(svg); | ||
|
||
expect(instructions.paints, const <Paint>[ | ||
Paint( | ||
stroke: Stroke(color: Color(0xff0000ff)), | ||
fill: Fill(color: Color(0xffff0000))), | ||
]); | ||
|
||
expect(instructions.paths, <Path>[ | ||
Path( | ||
commands: const <PathCommand>[ | ||
MoveToCommand(100.0, 10.0), | ||
LineToCommand(180.0, 10.0), | ||
LineToCommand(180.0, 90.0), | ||
LineToCommand(100.0, 90.0), | ||
CloseCommand(), | ||
], | ||
), | ||
]); | ||
}); | ||
|
||
test('stroke-width with unit value', () { | ||
const SvgTheme theme = SvgTheme(); | ||
|
||
const String svg_px = | ||
'<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><path d="M100 10 H180 V90 H100 Z" fill="#ff0000" stroke="#0000ff" stroke-width="1px"/></svg>'; | ||
const String svg_pt = | ||
'<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><path d="M100 10 H180 V90 H100 Z" fill="#ff0000" stroke="#0000ff" stroke-width="1pt"/></svg>'; | ||
const String svg_ex = | ||
'<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><path d="M100 10 H180 V90 H100 Z" fill="#ff0000" stroke="#0000ff" stroke-width="1ex"/></svg>'; | ||
const String svg_em = | ||
'<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><path d="M100 10 H180 V90 H100 Z" fill="#ff0000" stroke="#0000ff" stroke-width="1em"/></svg>'; | ||
const String svg_rem = | ||
'<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><path d="M100 10 H180 V90 H100 Z" fill="#ff0000" stroke="#0000ff" stroke-width="1rem"/></svg>'; | ||
|
||
final VectorInstructions instructionsPx = parseWithoutOptimizers(svg_px); | ||
final VectorInstructions instructionsPt = parseWithoutOptimizers(svg_pt); | ||
final VectorInstructions instructionsEx = parseWithoutOptimizers(svg_ex); | ||
final VectorInstructions instructionsEm = parseWithoutOptimizers(svg_em); | ||
final VectorInstructions instructionsRem = parseWithoutOptimizers(svg_rem); | ||
|
||
expect(instructionsPx.paints, <Paint>[ | ||
const Paint( | ||
stroke: Stroke(color: Color(0xff0000ff), width: 1.0), | ||
fill: Fill(color: Color(0xffff0000))), | ||
]); | ||
|
||
expect(instructionsPt.paints, <Paint>[ | ||
const Paint( | ||
stroke: Stroke(color: Color(0xff0000ff), width: 1 + 1 / 3), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is the 1/3 magic number coming from? A named constant might be helpful here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from the following documentation |
||
fill: Fill(color: Color(0xffff0000))), | ||
]); | ||
|
||
expect(instructionsEx.paints, <Paint>[ | ||
Paint( | ||
stroke: Stroke( | ||
color: const Color(0xff0000ff), width: 1.0 * theme.xHeight), | ||
fill: const Fill(color: Color(0xffff0000))), | ||
]); | ||
|
||
expect(instructionsEm.paints, <Paint>[ | ||
Paint( | ||
stroke: Stroke( | ||
color: const Color(0xff0000ff), width: 1.0 * theme.fontSize), | ||
fill: const Fill(color: Color(0xffff0000))), | ||
]); | ||
|
||
expect(instructionsRem.paints, <Paint>[ | ||
Paint( | ||
stroke: Stroke( | ||
color: const Color(0xff0000ff), width: 1.0 * theme.fontSize), | ||
fill: const Fill(color: Color(0xffff0000))), | ||
]); | ||
}); | ||
|
||
test('Dashed path', () { | ||
final VectorInstructions instructions = parseWithoutOptimizers( | ||
''' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like "Defaults stroke-width to 1 when an invalid value is parsed instead of throwing an exception"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will adjust this