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

Inline SVG attributes get lowercased #107

Open
dritter opened this issue Mar 22, 2021 · 1 comment
Open

Inline SVG attributes get lowercased #107

dritter opened this issue Mar 22, 2021 · 1 comment

Comments

@dritter
Copy link
Contributor

dritter commented Mar 22, 2021

Hi there,

the optimizer does not seem to respect the XML Namespace. As SVG is XML, and thus case sensitive (opposed to HTML, which is case insensitive), the SVG viewBox attribute gets lowercased by the amp-optimizer. Browsers seem to ignore the problem, so this is more a nitpick.

See the viewBox attribute here:

Before:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 137.7 25.1"><path d="M41 7.7l-1.2 2a4.4 4.4 0 0 0-3-.9 4 4 0 0 0-3.2 1.5 5.5 5.5 0 0 0-1.3 3.7 5.2 5.2 0 0 0 1.2 3.5 4 4 0 0 0 3 1.3 4.3 4.3 0 0 0 3.5-1.4l1.3 2a7 7 0 0 1-5 1.6 6.7 6.7 0 0 1-5-1.9 7.3 7.3 0 0 1-1.9-5.2 7.1 7.1 0 0 1 2-5.2 6.8 6.8 0 0 1 5.2-2 8.3 8.3 0 0 1 4.3 1m11.7 13.1v-6.2h-6.2v6.2h-2.8V6.9h2.8v5.5h6.2V6.9h2.7v13.9m6-11.7v3.2h5v2.1h-5v4.3h7v2.2h-9.8v-14h9.9v2.2m5.3 0v3.2h5.5v2.2h-5.5v6.3H71V6.9h10.3v2.2m11.3 11.7l-4.4-6-1.7 2.2v3.8h-2.8V6.9h2.8v6.7l5.3-6.7H95l-5 6 6 7.9m.5-7a7.3 7.3 0 0 1 1.8-5 6.2 6.2 0 0 1 4.9-2.1 6.8 6.8 0 0 1 5.1 1.8 7.2 7.2 0 0 1 1.8 5.2 7.5 7.5 0 0 1-1.8 5.4 7 7 0 0 1-5.3 2 6 6 0 0 1-4.8-2 8 8 0 0 1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3h-.2c-.1 0-.2.1-.2.3l1 15.3a.4.4 0 0 1-.4.4h-.5a.7.7 0 0 1-.7-.7l-1-15a.7.7 0 0 1 .3-.7 7.6 7.6 0 0 1 5.5-.8l.8-.1c4.2-.9 4.4-.9 8.2.3l1 .3a.7.7 0 0 1 .6.8z"></path></svg>

The w3c validator complains about the lowercased viewbox attribute when validated as SVG 1.1:
image

@westonruter
Copy link
Member

westonruter commented Mar 29, 2021

As you note, HTML is case insensitive (unlike XML), so it is expected that SVG inside of (AMP) HTML would get lower-cased. In fact, if I try running an SVG with a viewbox attribute through the W3C Validator and it has no complaints:

image

Source I used (notice viewbox not viewBox):

<!DOCTYPE html>
<html lang=en>
  <head>
    <title>SVG in HTML</title>
  </head>
  <body>
    <svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 137.7 25.1"><!--...--></svg>
  </body>
</html>

Therefore, I believe this is invalid.

Relates to ampproject/amp-wp#2045.

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

No branches or pull requests

2 participants