Skip to content
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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

fransdhinta
Copy link

@fransdhinta fransdhinta commented Nov 2, 2024

There is some issue while calling parseDouble from the original repo of this package issue link. I suggest a fix to change the return of parseDouble to always double.tryParse so that it will return null instead of throwing an error if it parses an invalid String

Fixes flutter/flutter#158819

Issue: link

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@jonahwilliams
Copy link
Member

Seems reasonable, but it needs a test. There are tests that validate that an svg string parses without exception. Maybe add one with an invalid double?

@fransdhinta
Copy link
Author

fransdhinta commented Nov 2, 2024

Seems reasonable, but it needs a test. There are tests that validate that an svg string parses without exception. Maybe add one with an invalid double?

using flutter_svg:

return Container(
    decoration: const BoxDecoration(color: Colors.blue),
    child: SvgPicture.string(
      '''svg_source''',
      width: 60.0,
      height: 80.0,
    ),
  );

@jonahwilliams this is the example svg that got invalid double error:

<svg xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny" width="100%" height="100%" viewBox="0 0 400 600" preserveAspectRatio="xMinYMin meet">
<g transform="scale(0.84 1) translate(38.0952380952381 0)">
<path fill="#5c3937" stroke="#000" stroke-width="6" d="M10 600s0-50 60-70 70-50 70-50l60-180 60 180s10 30 70 50 60 70 60 70" class="body"/>
</g>
<g transform="scale(0.84 1) translate(38.0952380952381 0)">
<g stroke="#000"><path fill="#89bfd3" stroke-width="6" d="M120 505c0 20 50 15 80 35 30-20 80-15 80-35 0 0 50-5 80 5 0 0 20 10 30 40s10 60 10 60H0s0-30 10-60 30-40 30-40c30-10 80-5 80-5Z" class="hockeyPrimary"/><path fill="#7a1319" stroke-width="none" d="m0 600 400 1.8-2-11.8s-8 5-18 5c-40-20-70-30-180-30C80 565 2 590 2 590z" class="lowStripe"/><path fill="#07364f" d="M4.5 577.03S10 580 20 580c30-15 110-20 180-20 90 0 150 5 180 20 10 0 17-2.97 17-2.97l1 12.97s-8 5-18 5c-40-20-110-22.48-180-22.48-80 0-150 2.48-180 22.48-10 0-18-5-18-5z" class="stripeAccent"/><path fill="#07364f" stroke-width="2" d="M120 505c0 20 50 15 80 30 30-15 80-10 80-30l15-1c0 41-40 21-95 56-55-35-95-15-95-56z" class="collarAccent"/><path fill="none" stroke-width="6" d="M120 505c0 20 50 15 80 35 30-20 80-15 80-35 0 0 50-5 80 5 0 0 20 10 30 40s10 60 10 60H0s0-30 10-60 30-40 30-40c30-10 80-5 80-5Z" class="hockeyStroke"/><path fill="#7a1319" stroke-width="2" d="M180 528.21h40l10 17.05L200 564l-30-18.74z" class="shieldSecondary"/></g>
</g>
<g transform="translate(32 290.6) scale(0.79 0.79) translate(6.11392405063291 9.144303797468353) translate(21.18 -3)">
<path fill="#5c3937" stroke="#000" stroke-width="6" d="M43 13S23 3 13 3 3 23 3 33s3 20 13 30 27-10 27-10z"/>
</g>
<g transform="translate(322 290.6) scale(-0.79 0.79) translate(-52.11392405063291 9.144303797468353) translate(21.18 -3)">
<path fill="#5c3937" stroke="#000" stroke-width="6" d="M43 13S23 3 13 3 3 23 3 33s3 20 13 30 27-10 27-10z"/>
</g>
<g transform="scale(0.8440000000000001 1) translate(36.96682464454974 0)">
<path fill="#5c3937" stroke="#000" stroke-width="6" d="M200 100c100 0 150 60 150 200 0 70-30 120-40 130l-60 60s-20 10-50 10-50-10-50-10l-60-60c-10-10-40-60-40-130 0-140 50-200 150-200Z" class="head"/><path fill="rgba(0,0,0,0)" d="M200 410c30 0 50 10 50 10 30 0 90-15 90-120h10c0 70-30 120-40 130l-60 60s-20 10-50 10-50-10-50-10l-60-60c-10-10-40-60-40-130h10c0 105 60 120 90 120 0 0 20-10 50-10" class="faceShave"/><path fill="rgba(0,0,0,0)" d="M60 300H50c0-140 50-200 150-200s150 60 150 200h-10v-10c0-5-10-20-15-25s-5-55-15-65c-40-40-60 0-110 0s-70-40-110 0c-10 10-10 60-15 65s-15 20-15 25z" class="headShave"/>
</g>
<g transform="translate(-113.85 -25) rotate(1 253.85 335)">
<path d="M265 360c-13.8 0-25-11.2-25-25s11.2-25 25-25 25 11.2 25 25-11.2 25-25 25" style="fill:none;stroke:#000;stroke-width:5;stroke-linecap:round;stroke-linejoin:round"/><path d="M265 360c-13.8 0-25-11.2-25-25v-5h50v5c0 13.8-11.2 25-25 25" style="stroke:#000;stroke-width:5;stroke-linecap:round;stroke-linejoin:round;fill:#fff"/><path d="M265 330c-10 0-10 15 0 15s10-15 0-15" style="stroke:#000;stroke-width:4;stroke-linecap:round;stroke-linejoin:round"/><path d="M217.7 324.9c1 1.5 3.4 4.7 7.5 6 2.7.9 5.2.6 7.1.5 2.2-.2 4.1-.7 5.4-1.1" style="fill:none;stroke:#000;stroke-width:5;stroke-linecap:round;stroke-linejoin:round"/>
</g>
<g transform="translate(6.150000000000006 -25) rotate(-1 253.85 335) scale(-1 1) translate(-507.7 0)">
<path d="M265 360c-13.8 0-25-11.2-25-25s11.2-25 25-25 25 11.2 25 25-11.2 25-25 25" style="fill:none;stroke:#000;stroke-width:5;stroke-linecap:round;stroke-linejoin:round"/><path d="M265 360c-13.8 0-25-11.2-25-25v-5h50v5c0 13.8-11.2 25-25 25" style="stroke:#000;stroke-width:5;stroke-linecap:round;stroke-linejoin:round;fill:#fff"/><path d="M265 330c-10 0-10 15 0 15s10-15 0-15" style="stroke:#000;stroke-width:4;stroke-linecap:round;stroke-linejoin:round"/><path d="M217.7 324.9c1 1.5 3.4 4.7 7.5 6 2.7.9 5.2.6 7.1.5 2.2-.2 4.1-.7 5.4-1.1" style="fill:none;stroke:#000;stroke-width:5;stroke-linecap:round;stroke-linejoin:round"/>
</g>
<g transform="translate(-30.051128272557094 119.74464674605963) rotate(3 170.0511282725571 150.25535325394037)">
<path fill="#272421" stroke="#000" d="M154.4 146.6c-.2-1.7-.3-2.7 0-3.4.8-2.2 5.8-2 9.2-2 4.6 0 8.9-.3 15.1 0 10 .4 19.5.5 22.3 3.4 2.6 2.7 2.6 5.5 2.6 5.5s.2.6 1.3 4.8c-1.2.1-3.1.1-5.3 0-4.2-.3-6.5-1.1-10.5-2-6-1.4-10.8-1.9-13.1-2-10.1-.7-15.1-1-17.1-.7-.7.1-2.9.5-3.9-.7-.3-.7-.4-1.5-.6-2.9zm-4.6-2.1c.3.3.2.7.4 1.8.1 1.2.2 1.3.3 1.6.4 2.1.7 2.3.7 2.7-.3 1.4-3.7 1.2-6.6 2-6.1 1.7-8.3 7.4-9.2 6.8-.8-.5.8-6.5 5.3-10.9 3-2.9 7.6-5.3 9.1-4z"/>
</g>
<g transform="translate(89.9488717274429 119.74464674605963) rotate(-3 170.0511282725571 150.25535325394037) scale(-1 1) translate(-340.1022565451142 0)">
<path fill="#272421" stroke="#000" d="M154.4 146.6c-.2-1.7-.3-2.7 0-3.4.8-2.2 5.8-2 9.2-2 4.6 0 8.9-.3 15.1 0 10 .4 19.5.5 22.3 3.4 2.6 2.7 2.6 5.5 2.6 5.5s.2.6 1.3 4.8c-1.2.1-3.1.1-5.3 0-4.2-.3-6.5-1.1-10.5-2-6-1.4-10.8-1.9-13.1-2-10.1-.7-15.1-1-17.1-.7-.7.1-2.9.5-3.9-.7-.3-.7-.4-1.5-.6-2.9zm-4.6-2.1c.3.3.2.7.4 1.8.1 1.2.2 1.3.3 1.6.4 2.1.7 2.3.7 2.7-.3 1.4-3.7 1.2-6.6 2-6.1 1.7-8.3 7.4-9.2 6.8-.8-.5.8-6.5 5.3-10.9 3-2.9 7.6-5.3 9.1-4z"/>
</g>
<g transform="translate(0 51.52119068455602) scale(-1 1) translate(-400 0)">
<path d="M168 384s9-13.77 32-14.03c17.4-.2 32 13.2 32 13.2s-4.29 23.24-32 23.81c-27.29.56-32-22.98-32-22.98" style="opacity:.05;mix-blend-mode:multiply;fill:#501414"/><path d="M168 384c12-4 48-4 64 0-20 4-10 4-32 4-20 0-16 0-32-4" style="fill:#fff"/><path d="M168 384c12-4 48-4 64 0-20 4-10 4-32 4-20 0-16 0-32-4Zm13.71 18.12c14.52 5.66 24.72 5.71 37.72-.71m.86-26.53c-14.52-5.66-27.29-6.34-40.29.09" style="fill:none;stroke:#000;stroke-width:3"/>
</g>
<g transform="translate(-4.045739644970411 -18.272994788737606) scale(-0.74 0.74) translate(-479.7832256516872 136.42024141225917)">
<path d="M180.17 380.08c1.6.3 3.5.1 4.8.9 4.7 2.8 9.2 6 13.8 9a10.23 10.23 0 0 0 11.7 0c3.9-2.5 7.8-5.1 11.7-7.6 1.6-1.1 3.3-2.2 5.7-3.8 0 2.1.4 3.4-.1 4.3-2.8 6.4-17.9 16.1-24.8 15-4-.6-8-2.8-11.3-5.3-4.3-3.3-7.8-7.5-11.6-11.4a4.5 4.5 0 0 0 .1-1.1"/>
</g>
<g transform="scale(-1 1) translate(-400.1385485503768 0) scale(0.8440000000000001 1) translate(36.97962889446608 0)">
<g fill="#272421" stroke="#000" stroke-width="4"><path d="M410.1 326.4c-7 23.9-14.2 47.7-21 71.6-.9 3.6-1.3 7.2-1.4 11-.6 8.8 3.2 15.9 9.9 21.9 1.4 1.2 1.8 3.3 2.6 5-2 .4-4.4 1.6-6.3 1.3-9.5-1.5-18-6.6-23.5-14.1-3.1-4.3-6.9-8.2-11.1-11.7 3.9 7.9 7.5 15.9 11.6 23.9 1.9 3.8 4.5 7.4 6.6 11.1.5.9.2 2.1.3 3.1-1.1-.4-2.8-.4-3.4-1.2-4.8-7-9.3-14.2-14.1-21.2-11.3-16.4-21-33.6-24.8-53.2-.2-.6-.5-1.1-.9-1.6-8.9 9.8-13.8 21-14.4 33.7-.9 17.5.6 34.5 7.1 51.1.7 1.7.8 3.6.3 5.4-.8-.4-1.5-1-2.1-1.6-11.2-16.9-17.5-36.2-18.4-56.1-.9-20.7 5.9-39.5 18.1-56.6 1.1-1.5 1.3-3.9 1.1-5.8-.6-7-1.5-14-2.3-21.1-4.3 6.3-5.5 14.4-13.1 19.2 0-10.4.4-20.1-.1-29.7-.4-7-.9-14.3-2.9-21.1-2.3-7.8-6.3-15.3-9.9-22.7-1.2-2-3-3.6-5.3-4.6-26.1-12.4-50.6-27-72.3-45.5-6.1-5.2-11.7-11.1-17.3-16.3-25.6 27-57.3 46.4-91.7 62.4-2.4 1.2-4.7 2.8-6.5 4.8-4.7 4.5-9.1 9.2-13.3 14.2-2.5 3-4.4 6.6-5.4 10.4-3.5 14.9-3.1 30-2.8 45.2v4.1c-4.3-.3-5-3.3-5.6-6.2-2.2-11.3-4.3-22.5-6.6-33.7-1.9-9.6-4.3-19.2-6.5-28.8-.4-1.4-1.4-2.6-2.8-3.3.3 2.8.4 5.7.9 8.4 1.6 8.7-.1 16.9-3.5 25-4.9 11.7-9.8 23.4-14.4 35.2-.9 2.3-1 5.7.1 7.7 14.5 27.6 30.6 54.2 53.9 76.2.7.6 1.3 1.2 1.8 1.9.2.2.1.5.1.8-10.3 2.5-46-27.1-65.6-54.8-1.3 13.4-2 25.7 4 37.7 5.7 11.5 13.3 21.7 22 31.5l-.8 1c-9.3-5.7-18.8-11.4-28.2-17.2-8.8 7.4-18.9 12.1-32 12.4 1.5-1.2 2.2-1.8 3-2.3 7.9-5.8 9.2-13.8 8.6-22.5-1.1-17.9-7.5-34.5-15.8-50.3-4.6-8.8-6.8-17.7-6-27.1.9-12.5.5-25.1 4-37.6 3.1-11.1 8-21 16.3-29.2 9-9 18.5-17.6 27.6-26.4 1.2-1.2 2.5-3.1 2.4-4.7-.7-9.4 2.1-18.9 8.1-26.5 4.3-5.7 9.3-10.7 13.8-16.1 1.8-2.3 4-5 4.7-7.7 8.5-31.4 29-54.1 57.9-70.6 8.7-5 18.1-9.2 27.4-13.4 10.7-4.8 22.5-6.5 34.2-4.9 14.2 1.9 28.4 2.9 42.9 1 9.5-1.2 18.6 1.6 27.2 5.1 26.8 11.1 50.5 25.9 67.4 48.8 7.9 10.6 12.6 22.4 16.5 34.7 1.1 2.8 2.6 5.4 4.7 7.7 5.7 7.5 12.2 14.4 17.5 22.2 4.6 6.9 5.7 14.9 3.9 23-.7 3 .5 4.7 2.3 6.9 9.7 11.4 19.7 22.7 28.7 34.7 6.9 9.1 10.6 19.9 12 31.2.2.8.5 1.7.8 2.4-.2 3.8-.2 8.1-.2 12.5zM64.8 232.9c5.3-10 13.1-18.8 22.7-25.4 13-9 25.7-18.2 39.3-26.4 22.1-13.7 46.2-23.2 73.2-26.1.7-5.7 1.4-11.7 2.2-18.6-9.9 0-19.4-1-28.6.2-32.1 4.1-61.5 15.3-88.3 32.3-7.4 4.7-13.4 10.3-15.5 19.7-3.4 14.6-5.5 29.2-5 44.3.2 3.3.5 6.7.6 10 .1 4 2.3 5.3 6.1 4.3 5.7-1.5 11.7-2.5 16.9-5 12.7-5.7 25.9-10.7 37.4-18.2 24.3-15.9 47.6-33.2 71.3-50 1-.6 1.7-1.6 2-2.7.5-4.6.6-9.2.9-15.4-11.3 2.8-21.8 4.5-31.7 8-38.7 14.3-72.3 35.6-99.7 65.2-1.2 1.3-2.5 2.6-3.8 3.8zm237.3 33.8c3.8 10.8 9.1 21.3 11 32.5 1.8 11 .4 22.3.4 33.3 5-7 10.6-22.3 12.2-30.8 1.7-9.2 3.6-18.4 10.2-26.1 1.9-2.2 4.1-5 4.4-7.7.6-5 0-10.3-.6-15.2-.1-1-2.1-2.4-3.5-2.6-22.1-2.4-42.2-10.4-61.4-20.6-26.4-14-49.1-33.3-66.8-56.4-1.1-1.7-2.2-3.6-3.1-5.5 1.1.1 1.5 0 1.7.2.4.4.9.8 1.2 1.3 16 21.1 36.3 39.1 59.9 52.7 20.4 12 42 21.1 66.3 24.1 2.5.3 5.1.3 7 .4 4.4-10.4.4-17.2-8.1-23.6-14.1-10.8-28.6-20.8-44.7-29-22.7-11.6-45.6-22.6-70.5-29.6-4.7-1.3-9.5-1.6-14.9-2.4 0 9.2.1 17.5 0 25.7-.1 5.7 1.8 10.9 6.2 14.7 8.5 7.9 17 16 26.4 23 19.3 14.6 39.8 27.4 62.8 36.4l32.7 13c.3.1.5.6.6.9l-.6 1.2q-15-4.95-28.8-9.9zM203 159.5c27.3 2.6 50.5 15 74.1 26 23.7 11 45.7 24.6 65.5 43-.5-13.8-1.6-26.3-5.1-38.4-1.7-6.2-3.5-12.2-8.7-16.5-10.1-8.5-19.7-17.7-30.4-25.7-15.8-12-34.1-17.7-54.3-13.3-10.4 2.1-20.3 5.7-30.2 9.2-12 4.5-10.7 5.2-10.9 15.7zM359.2 252c3.1 2.5 6.1 4.7 8.6 7.1 16.1 15.5 27.5 49.8 5.2 74.7-6.2 6.8-12.7 13.3-19.6 19.5-4.1 3.7-5.9 7-4.6 12.3 1 4.3.7 8.7 1.3 13.1 1.3 10.7 3.1 21.2 11.2 29.7 6.2 6.6 12.1 13.5 18.8 19.6 4.1 3.7 9.2 6.8 15.5 5.9.1-.6.2-.8.1-.9-.4-.5-.8-.9-1.2-1.3-7.8-5.3-11.1-12.7-10.6-21.4.4-6.3.8-12.7 2.7-18.7 4.8-15.1 10.4-30.1 15.5-45.1 8.8-25.4 5.5-49.1-10.6-71.3-8-11.1-16.7-21.6-26.9-31.1-2 2.8-3.7 5.5-5.4 7.9zM80.3 323.7c.5-6.6.8-13.3 1.3-20 .7-11 2.9-21.2 12.6-28.8 2-1.6 3.6-4.1 5.4-6.1-8.1 1.8-15.4 5.1-23.4 5.7 2.4-1.4 5.2-2.1 7.7-3 27.7-9.5 53.9-22.9 77.5-39.7 13-9.2 24.7-20.2 36.8-30.4 1.7-1.6 2.7-3.9 2.8-6.2-.3-6.1-1.3-12.1-2.1-18.6-1.3 1-2.2 1.6-3.1 2.3-17 12.4-33.7 25.3-51.2 37.1-22.7 15.5-46.7 28.9-74.7 34.4-.9.2-1.7.8-2.2 1.6-2.9 6-1 15.8 2.4 19.2-.4 2.6-1.1 4.4-.8 5.7 3.4 15.7 7.3 31.2 11 46.8zM6.9 378c.4-4.4.5-8.7 1.1-13 1.8-11.1 8.1-20.4 14.1-29.9 2.5-4.1 4.7-7.7 4.6-13.2-.3-15.7 2.5-31.4 9.7-45.8 4.1-7.7 6.5-16.2 6.9-24.9.2-3.7-.7-7.5-1.1-11.2-.7-.2-1.3-.3-2-.4-11.5 12-23.2 23.7-34.2 35.9-3.5 3.9-5.6 9.1-7.5 14.1-6.9 18.4-6.9 37.4-6 56.4.2 1.9.8 3.8 1.7 5.5 4 8.8 8.4 17.4 12.7 26.5zm344.9-115.9c7.6 7.6 11.1 16.4 10.4 26.3-1.2 15.8-9.3 29.6-18.3 42.6-4.6 6.7-11 12.3-15.7 18.8-19.4 26.2-22.3 54.5-12.2 84.5.6 1.5.9 3 1.6 4.6.6 1.3 1.2 2.5 1.4 3-.6-10.3-1.1-21.1-1.7-32.1-.8-17.2 7.4-31.4 18.1-44 7.3-8.7 17.1-15.5 25.6-23.4 7.7-7.1 14.8-14.9 18.3-24.7 7-19.6 1.6-37.1-10.5-53.5-2.8-3.8-6.8-6.9-10.7-10.6-2.5 3.4-4.4 5.7-6.3 8.5zM54 260.8c1.9 17.1-4.7 31.5-12.7 45.5-6.4 11.3-13.1 22.3-19.9 33.4C15.3 349.8 9 360 9.3 372.1c.4 31.2 17.2 47.3 43.7 60.4 0-.1.1-.3 0-.3-1.1-1.6-2.2-3.1-3.5-4.7-17.6-21-21.4-44.7-13.2-69.8 5.1-16 11.3-31.7 18.4-47 6-12.8 7.5-25.5 5.8-39-.5-4.5-1.9-7.8-6.5-10.9zm20.7-86.7c27.2-21.7 58.4-33.5 92.1-40 11.7-2.3 23.3-1.3 35.7 1.5-.6-3.5.1-7.1-1.6-8.8-7.5-7.7-16.3-14.2-28-14.3-10.9-.1-21.8.4-32.7 1.4-4.5.3-9.6 1.2-13.2 3.6-9.7 6.3-19.1 13.2-27.9 20.6-11.2 9.6-18.9 21.7-24.4 36zm254.6-3.9c.3-.2.5-.3.7-.5-.1-.5-.3-1.1-.6-1.6-1-2-1.9-4-3.1-5.9-12.8-22.3-32.9-37.4-55.9-49.2-1.8-.8-3.8-1.3-5.8-1.3-20.5-.7-39.2 4.9-57 13.7-.6.3-1.1.9-1.2 1.6-.6 6.2-1.2 12.4-1.8 18.5 12.5-5.7 25.4-10.6 39.1-13.2 25.4-4.9 46.5 2.9 64.7 19.2zm.5 172.4c4.3-5.1 7.6-9 10.8-13.2.7-1.1 1-2.4.7-3.7-2-10.6.2-20.3 5.6-29.6 3-5.1 5.7-10.4 8-15.7 2.8-6.8 1.3-10.7-4.9-15.7-3 2.7-6.2 5.4-9.1 8.2-1.8 1.6-3.5 3.5-4.8 5.6-4.4 8.3-6.6 17.3-7.5 26.5-1.3 12.1-.6 24.1 1.2 37.6zm-288.7 4.3c-.9 3.3-2 6.8-3.2 10-2 5-1.1 9.2 1.7 13.7 11.4 18 27.1 33.2 45.9 44.4.3.2.7.2 1.1.2-7.9-11.1-16-21.8-23.6-33.1-7.6-11.5-14.5-23.1-21.9-35.2zm99-236.1c22.6-2.3 44.7-4.8 62.1 13.9.6-7.7 1.3-14.1 1.6-20.5 0-1-1.3-2.7-2.2-2.9-21.4-3.7-41.9-2.9-61.5 9.5zm66.2 11.4c8.7-3.2 17.1-7 25.9-9.3s18.2-3.3 26.8-5c-11-7.6-35.5-10.1-51.7-5-.3 6.5-.6 13.1-1 19.3zM51 256.6c-13.6 15.8-11.8 33.8-13.6 51.2 12.4-18.6 17.5-36.9 13.6-51.2zM345.5 361c-2 1.8-2.9 2.7-3.9 3.5-4.4 3-5.2 6.7-3.1 11.5 2 5 2.9 10.3 5.1 15 4.3 9.1 9 18.1 13.6 27 .6-.2 1.1-.4 1.8-.6-8.9-17.6-13.5-36.9-13.5-56.4zm13.1-80c-6.4 14-19 26.3-14.9 44.5 9.6-14.1 16.5-27.9 14.9-44.5zm-296-15.1c.6-.1 1.2-.3 1.8-.3 0-6.4.3-12.9-.1-19.3-.4-5.5-1.6-11-2.1-16.3-.2-2.6-.2-5.3-.1-7.8l-2.3-.3c-1.5 6.2-3.9 12.3-4.4 18.5-.5 6.1-1.9 12.7 4.2 18.6-2-.4-2.7-.6-4.2-1 2.6 2.9 4.9 5.5 7.2 7.9zm282.9-43.2c-.3 4.5-.2 8.8-.8 13-1.5 10-4.3 20.1-.4 30 11.2-9.1 9.2-34.4 1.2-43zM54.4 256.2c-.6-1.8-1-3.8-1.3-5.7-.8-9.7.5-19.3 5.8-27.9 2.9-4.7 3.9-7.9 2.6-13.7-7.5 8.1-12.7 16.6-14.3 27.6-1.1 7 .9 11.7 5 16.6.6.7 1 1.5 2.2 3.1zM12.8 401c1.4 11.2 3.1 22.4-6.4 31.8.4.3.6.6 1 .9 7.6-4.1 15.1-8.1 22.2-11.9-6-7.5-11.4-14.1-16.8-20.8zm332.4-190.9c.2 5.1-1.1 10.6 3.8 14.6 1.1 1 1.7 2.8 2 4.4 1.3 6.3 2.3 12.6 3.6 19 .3 1 .7 1.9 1.2 2.9 1-.7 2-1.4 2.9-2.2 2.9-3 .9-6.6.9-10-.1-11.9-6.3-20.6-14.4-28.7zM63.9 195.3c-16.3 15.1-24.5 32.8-18 43.9-.6-12 4.7-21.3 12.5-29.5 4.1-4.1 5.6-8.7 5.5-14.4zm279.8 1.1c-.5.2-.9.3-1.3.4 1.3 3.7 1.7 7.9 4.2 10.8 7.6 9 14.9 18.1 14.8 31 6.7-10.8-3.4-28.9-17.7-42.2zM29.1 323.1c3.7-5.1 6-9.2 5.7-14.6-.3-5 .6-10.3 1.2-15.2.4-3.7.9-7.1 1.5-10.7-6 12.6-7.5 26-8.4 40.5zm16.1-73.7c-.4 3.7-.7 6.8-1 9.9 2.5-2.9 6.6-5.9 1-9.9z"/><path d="M302.1 266.7c9.2 3.1 18.9 6.5 28.5 9.8l.6-1.2c-.2-.3-.4-.8-.6-.9l-32.7-12.9c-23-9-43.6-21.8-62.8-36.4-9.3-7.1-17.8-15.2-26.4-23-4.3-3.9-6.2-9-6.2-14.7.1-8.2 0-16.3 0-25.7 5.4.9 10.4 1.1 14.9 2.4 24.9 7 47.9 18.1 70.5 29.6 15.9 8.1 30.6 18.2 44.7 29 8.4 6.4 12.3 13.2 8.1 23.6-2.3 0-4.7-.2-7-.4-24.3-2.8-45.9-12.1-66.3-24.1-23.6-13.6-43.9-31.6-59.9-52.7-.4-.5-.8-.9-1.2-1.3-.2-.2-.6-.1-1.7-.2.9 1.9 1.9 3.8 3.1 5.5 17.7 23.1 40.5 42.3 66.8 56.4 19.2 10.4 39.3 18.2 61.4 20.6 1.3.2 3.4 1.6 3.5 2.6.6 5 1.1 10.3.6 15.2-.3 2.6-2.3 5.5-4.4 7.7-6.6 7.7-8.5 16.8-10.2 26.1-1.5 8.4-7.2 23.8-12.2 30.8 0-11 1.5-22.3-.4-33.3-1.6-11.1-7-21.6-10.7-32.5z"/><path d="M203 159.5c.2-10.6-1.2-11.3 10.9-15.7 9.8-3.7 19.9-7.1 30.2-9.2 20.3-4.3 38.6 1.3 54.3 13.3 10.6 8 20.2 17.1 30.4 25.7 5.3 4.5 7 10.4 8.7 16.5 3.4 12.3 4.6 24.7 5.1 38.4-19.8-18.5-41.7-32.1-65.5-43-23.7-10.8-46.8-23.3-74.1-26zm156.2 92.6c1.7-2.4 3.4-5 5.4-7.9 10.4 9.5 19 20.1 26.9 31.1 16 22.1 19.6 45.9 10.6 71.3-5.3 15-10.8 29.9-15.5 45.1-1.8 6-2.3 12.4-2.7 18.7-.5 8.7 2.8 16.1 10.6 21.4.5.4.9.8 1.2 1.3.1.1 0 .3-.1.9-6.4.8-11.6-2.3-15.5-5.9-6.8-6.1-12.7-13-18.8-19.6-8-8.4-9.8-19.1-11.2-29.7-.6-4.4-.2-8.9-1.3-13.1-1.3-5.3.6-8.6 4.6-12.3 6.9-6.1 13.5-12.6 19.6-19.5 22.3-24.9 11-59.2-5.2-74.7-2.5-2.5-5.4-4.6-8.6-7.1zM64.8 232.9c1.3-1.2 2.6-2.4 3.9-3.8 27.4-29.5 61.1-50.8 99.7-65.2 9.7-3.7 20.3-5.2 31.7-8-.4 6.2-.5 10.9-.9 15.4-.1 1-1.1 2-2 2.7-23.8 16.7-47 34.1-71.4 50-11.4 7.5-24.7 12.5-37.4 18.2-5.3 2.3-11.3 3.3-16.9 5-3.9 1-6-.3-6.1-4.3-.1-3.3-.3-6.6-.6-10z"/><path d="M64.9 232.9c-.5-15 1.5-29.7 4.9-44.5 2.1-9.4 8.1-14.9 15.5-19.7 26.8-16.9 56.2-28.2 88.3-32.3 9.2-1.1 18.6-.2 28.6-.2-.8 7-1.6 12.9-2.2 18.6-27.1 2.8-51.1 12.4-73.2 26.1-13.4 8.3-26.3 17.5-39.3 26.4-9.6 6.7-17.3 15.5-22.6 25.6zm15.4 90.9c-3.9-15.6-7.7-31.1-11.4-46.7-.4-1.4.4-3 .8-5.7-3.5-3.2-5.4-13.2-2.4-19.2.5-.8 1.3-1.3 2.2-1.6 28-5.6 52-19.1 74.7-34.4 17.5-11.9 34.1-24.8 51.2-37.1.9-.7 1.8-1.4 3.1-2.3.8 6.5 1.8 12.5 2.1 18.6-.1 2.3-1.1 4.6-2.8 6.2-12.1 10.4-23.9 21.2-36.8 30.4-23.6 16.7-49.6 30.1-77.5 39.7-2.6.7-5.3 1.7-7.7 3 8-.6 15.3-3.8 23.4-5.7-1.8 2-3.1 4.4-5.4 6.1-9.6 7.6-11.9 17.9-12.6 28.8-.1 6.6-.5 13.2-.9 19.9zM6.9 378c-4.4-8.9-8.6-17.7-12.8-26.5-.9-1.7-1.5-3.6-1.7-5.5-.9-19.1-.9-38.2 6-56.4 1.8-5 4-10.1 7.5-14.1 11.2-12.4 22.8-24.1 34.3-35.9.7.2 1.3.3 2 .4.4 3.7 1.2 7.5 1.1 11.2-.5 8.6-2.8 17.1-6.9 24.9-7.2 14.4-10.1 30-9.7 45.8.1 5.6-2.1 9.1-4.6 13.2C16.2 344.6 10 354 8 365c-.8 4.2-.8 8.6-1.1 13zm344.9-115.9c1.9-2.7 3.8-5.1 6.2-8.4 3.8 3.7 7.8 6.7 10.7 10.6 12 16.3 17.5 33.9 10.5 53.5-3.6 9.7-10.6 17.6-18.3 24.7-8.4 7.8-18.2 14.7-25.6 23.4-10.7 12.7-19 26.9-18.1 44 .6 11 1.1 21.8 1.7 32.1-.2-.4-.8-1.6-1.4-3-.6-1.5-1-3-1.6-4.6-10.2-29.9-7.2-58.5 12.2-84.5 4.9-6.5 11.3-12.1 15.7-18.8 8.9-13 17.1-26.8 18.3-42.6.8-9.9-2.7-18.8-10.3-26.4z"/><path d="M54 260.8c4.6 3.1 6 6.5 6.6 11 1.7 13.6.2 26.3-5.8 39-7.3 15.2-13.5 30.9-18.6 46.9-8.1 25.1-4.4 48.7 13.2 69.8 1.2 1.5 2.3 3 3.5 4.7.1.1 0 .3 0 .3-26.6-13.2-43.3-29.2-43.7-60.4-.2-12.1 6.1-22.3 12.2-32.4 6.8-11.1 13.5-22.1 19.9-33.4 8-14 14.7-28.4 12.7-45.5zm20.7-86.7c5.5-14.2 13.2-26.4 24.5-36 8.8-7.4 18.1-14.3 27.9-20.6 3.6-2.3 8.7-3.1 13.2-3.6 10.9-1 21.7-1.4 32.7-1.4 11.8.3 20.5 6.7 28 14.3 1.7 1.6 1 5.4 1.6 8.8-12.6-2.8-24.2-3.8-35.7-1.5-33.8 6.5-65 18.1-92.2 40zm254.6-3.9-20.9-18.9c-18.2-16.3-39.3-24.1-64.7-19.2-13.7 2.6-26.6 7.5-39.1 13.2.6-6.2 1.1-12.4 1.8-18.5.2-.6.6-1.2 1.2-1.6 17.9-8.8 36.7-14.4 57-13.7 2 0 4 .5 5.8 1.3 23 12 43.2 27 55.9 49.2 1.1 1.9 2 4 3.1 5.9.2.5.4 1 .6 1.6zm.4 172.4c-1.8-13.5-2.3-25.6-1-37.7 1-9.2 3.1-18.2 7.5-26.5 1.3-2 2.8-4 4.8-5.6 2.9-2.8 6.1-5.5 9.1-8.2 6.2 5 7.7 8.9 4.9 15.7-2.2 5.4-5 10.7-8 15.7-5.5 9.3-7.7 19.1-5.6 29.6.2 1.3 0 2.6-.7 3.7-3.3 4.3-6.8 8.3-11 13.3z"/><path d="M41.1 346.9c7.4 11.9 14.3 23.8 21.9 35 7.6 11.4 15.6 22.2 23.6 33.2-.4.1-.8 0-1.1-.2-18.9-11.1-34.6-26.3-45.9-44.4-2.8-4.5-3.8-8.8-1.7-13.7 1.3-3.1 2.3-6.5 3.2-9.9zm99-236.1c19.6-12.4 40.2-13.2 61.5-9.5.9.2 2.2 1.9 2.2 2.9-.3 6.4-.9 12.8-1.6 20.5-17.3-18.7-39.4-16.2-62.1-13.9zm66.2 11.4c.3-6.3.6-12.8.9-19.3 16.1-5.1 40.8-2.5 51.7 5-8.7 1.5-18.1 2.5-26.8 5-8.5 2.3-16.9 6.1-25.8 9.3zM51 256.6c4 14.3-1.2 32.7-13.6 51.1 1.8-17.3.1-35.3 13.6-51.1zM345.5 361c0 19.5 4.6 38.7 13.4 56.3-.6.2-1.1.4-1.8.6-4.6-9-9.3-17.9-13.6-27-2.2-4.8-3.1-10.1-5.1-15-1.9-4.8-1.1-8.3 3.1-11.5 1.1-.8 1.9-1.7 4-3.4zm13.1-80c1.6 16.3-5.4 30.3-14.9 44.5-4.1-18.2 8.5-30.4 14.9-44.5zm-296-15.1c-2.2-2.5-4.6-5-7.2-8 1.4.3 2 .4 4.2 1-6.1-5.9-4.6-12.5-4.2-18.6.5-6.3 2.8-12.4 4.4-18.5l2.3.3c-.2 2.6-.1 5.3.1 7.8.6 5.5 1.8 11 2.1 16.3.4 6.4.1 12.9.1 19.3-.6.2-1.2.3-1.8.4zm282.9-43.2c8 8.5 9.9 33.8-1.1 43-3.9-9.9-1.1-20 .4-30 .5-4.2.5-8.5.7-13z"/><path d="M54.4 256.2c-1.2-1.6-1.7-2.3-2.2-3-4.1-5-6.1-9.6-5-16.6 1.7-11 6.8-19.6 14.3-27.6 1.2 5.8.2 9-2.6 13.7-5.4 8.6-6.7 18.2-5.8 27.9.3 1.9.8 3.7 1.3 5.6zM12.8 401c5.5 6.8 10.8 13.3 16.9 20.8-7 3.8-14.6 7.8-22.2 11.9-.4-.3-.6-.6-1-.9 9.5-9.5 7.7-20.7 6.3-31.8zm332.4-190.9c8.1 8.2 14.3 16.9 14.3 28.6 0 3.5 1.9 7-.9 10-.9.8-1.8 1.5-2.9 2.2-.5-.9-.9-1.9-1.2-2.9-1.2-6.4-2.2-12.6-3.6-19-.3-1.5-.8-3.3-2-4.4-4.8-4.1-3.5-9.4-3.7-14.5z"/><path d="M63.9 195.3c.1 5.8-1.4 10.4-5.4 14.4-7.9 8.1-13.2 17.5-12.5 29.5-6.7-11.2 1.5-28.9 17.9-43.9zm279.8 1.1c14.3 13.2 24.3 31.4 17.6 42 .1-12.9-7.2-21.8-14.8-31-2.3-2.8-2.8-7.1-4.2-10.8.5.1 1 0 1.4-.2zM29.1 323.1c.8-14.5 2.3-28 8.4-40.6-.5 3.6-1.1 7.1-1.5 10.7-.6 5.1-1.5 10.3-1.2 15.2.2 5.5-2.1 9.7-5.7 14.7zm16.1-73.6c5.6 4.1 1.5 6.9-1 9.9.3-3.2.6-6.4 1-9.9z"/></g>
</g>
<g transform="scale(0.8440000000000001 1) translate(36.96682464454974 0)">
<g stroke-width="2"><path fill="rgba(150,150,175,.5)" fill-rule="evenodd" stroke="#000" d="M200 190c50 0 100 10 110 20s20 80 20 80 0 60-10 70-50 10-80 10c-10 0-20-10-40-10s-30 10-40 10c-30 0-70 0-80-10s-10-70-10-70 10-70 20-80 60-20 110-20Zm-70 90q-45 0-45 30c0 25 15 30 45 30s60-5 60-30-30-30-60-30Zm140 60c30 0 45-5 45-30q0-30-45-30c-30 0-60 5-60 30s30 30 60 30Z" class="facemask"/><path fill="#333" stroke="#000" d="M350 315v-30h-20v30zm-280 0v-30H50v30z" class="straps"/><path fill="none" stroke="#fff" d="m260 270 10-30m0 35 10-30m-160 25 10-30m0 35 10-30m120 115 5-15m0 20 5-15m-150 10 5-15m0 20 5-15" class="glare"/></g>
</g>
</svg>

@fransdhinta
Copy link
Author

@jonahwilliams i have added a test

@@ -81,7 +77,6 @@ double? parseDoubleWithUnits(
}
final double? value = parseDouble(
rawDouble,
tryParse: tryParse,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tryParse parameter to parseDoubleWithUnits is now ignored; we should not have parameters that don't do anything.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will check it

@@ -172,6 +172,10 @@ void main() {
expect(parseDoubleWithUnits('1pt', theme: const SvgTheme()), 1 + 1 / 3);
});

test('"none" conversion', () {
expect(parseDoubleWithUnits('none', theme: const SvgTheme()), null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is testing the specific change to the parsing function, but isn't testing anything related to the original issue. It's not at all clear from the change and the test what actually happens now in the original case of the issue this PR is intended to fix. Does returning null instead of throwing work, or does it just create a different issue elsewhere in that codepath?

If the goal is to fix the case of an SVG with percentage values or none values, we should have a test that exercises that, and ensures that the higher-level behavior is as desired with this change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @stuartmorgan , what kind of test cases need to be added, do you have any suggestions?
currently I am also trying to read the documentation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You provided an SVG that triggered this error in a comment above; a test that parsed a minimal version of that SVG and ensured that it behaved as expected seems like it would give good coverage of this use case.

@@ -1,3 +1,7 @@
## 1.1.13

* Fixes an issue when parse double with 'none' value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a period; see the PR checklist link for CHANGELOG style.

@@ -1,3 +1,7 @@
## 1.1.13

* Fixes an issue when parse double with 'none' value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"when parsing a double with a value of 'none'."

return double.tryParse(rawDouble);
}
return double.parse(rawDouble);
return double.tryParse(rawDouble) ?? 0.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this returning 0.0 instead of null for an invalid value?

test('Parse SVG with "none" value', () {
final TestColorMapper mapper = TestColorMapper();
final SvgParser parser = SvgParser(
'<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg"><rect x="100" y="10" width="80" height="80" fill="red" stroke-width="none" /></svg>',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an SVG spec reference documenting none as a valid numeric value? I'm not very familiar with the spec, but I didn't see anything indicating that this would be valid.

It's not clear to me that silently treating invalid values in SVG files as zero is a desirable change. Is there a standard for how SVG parsing and failure handling are supposed to work, or is it client-specific?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I'm reading from SVG spec here https://svgwg.org/svg2-draft/geometry.html#Sizing is that width/height are treated as CSS properties, and in CSS i believe none clears a previously established default from the cascade. Its not meaningful for SVGs parsed by this library since we don't actually support CSS, but given that folks drop SVGs from external systems in here I think its reasonable to 'support' it by being tolerant of the value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should none have special handling? That would be a very different fix from what the current code in the PR is doing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none would clear out the old default, but there will never be any old default. So treating it as if the width/height wasn't specified. I don't think just returning null or 0 will work, as this needs to behave as if the attribute was not specified at all.

This means that the handling will need to be slightly different per property. So for stroke-width, for example, we need to instead treat none special and pretend there is no stroke properties here:

https://github.com/flutter/packages/blob/main/packages/vector_graphics_compiler/lib/src/svg/parser.dart#L1547-L1557

Then do something similar for fill.

My understanding is those are the properties from the specified SVG that are causing problems. Returning 0 might be correct for certain properties like width/height or incorrect for others.

@@ -980,7 +980,6 @@ class SvgParser {
}) {
return numbers.parseDoubleWithUnits(
rawDouble,
tryParse: tryParse,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has recreated the same problem, just one level up; the tryParse parameter is now ignored in this method.

If removing tryParse is in fact the correct behavior, it needs to be done in a comprehensive and consistent way. Any version that leaves options at other levels of the code that are silently ignored isn't going to pass review.

@fransdhinta fransdhinta changed the title [vector_graphics_compiler] fix: remove tryParse attribute on parseDouble [vector_graphics_compiler] fix: handle parsing stroke-width with an invalid value Nov 9, 2024
@fransdhinta
Copy link
Author

fransdhinta commented Nov 10, 2024

Hi @stuartmorgan and @jonahwilliams , apologies for the delayed response. After reading and studying the SVG documentation, I found that each property may have different types of values and default values, meaning that modifying the parseDouble implementation could lead to invalid results in many cases.

stroke-width: docs

Therefore, I’ve decided that this PR will focus solely on improving the implementation for parsing stroke-width, which is the specific issue I encountered in the reported problem.

To address this, I have added special handling for parsing stroke-width and reverted the parseDouble implementation to its original state. I have also updated the title of this PR accordingly.

However, eventually, there will need to be additional handling for percentage values, which are currently not supported by the parseDouble function, may add this in a separate PR.

try {
return parseDoubleWithUnits(rawWidth);
} on FormatException catch (e) {
switch (e.message) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this switch?

} on FormatException catch (e) {
switch (e.message) {
case 'Invalid double':
return 1.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking for an answer to this question I had earlier:

Is there a standard for how SVG parsing and failure handling are supposed to work, or is it client-specific?

and it appears that the spec says to ignore invalid values. The definition of ignored that it links to says "[the UA] treats it as if it wasn’t there at all."

Given that, I'm not clear on why there's a special wrapper returning 1.0, rather than just using tryParse: true when parsing the width.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, previously I tried rendering an SVG in the browser and found that if it was given an invalid value then the result rendered was the same as stroke-width with initial value 1 as in the following docs, apparently I missed testing if the value/property was not defined,
it turns out displayed the same result, which means that if the value provided is invalid it will be ignored as stated in the docs.

so yes this special wrapper is not needed, adding tryParse: true when parsing stroke-width is enough

@@ -1,3 +1,7 @@
## 1.1.16

* Fixes an issue when parsing stroke-width with an invalid value
Copy link
Member

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"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will adjust this

Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nit

@@ -1,3 +1,7 @@
## 1.1.16

* Fixes an issue when parsing stroke-width with an invalid value
Copy link
Contributor

Choose a reason for hiding this comment

The 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.


expect(instructionsPt.paints, <Paint>[
const Paint(
stroke: Stroke(color: Color(0xff0000ff), width: 1 + 1 / 3),
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the following documentation
it is stated that 1pt is 1/72 of 1in, and the value of 1in = 96 so the formula is 1/72*96 or 96/72 or 4/3 or 1 + 1/3. I think i'll change the test to pt * 96/72

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flutter_svg] Invalid double
3 participants