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

Space removal for the "arcto" command is not affected by noSpaceAfterFlags #1403

Closed
NeRdTheNed opened this issue Mar 4, 2021 · 1 comment

Comments

@NeRdTheNed
Copy link

NeRdTheNed commented Mar 4, 2021

Describe the bug
When a SVG file containing "arcto" commands ('a' or 'A') is optimised, setting the plugin parameter "noSpaceAfterFlags" to true for relevant plugins does not result in "unnecessary" spaces (required for some programs) being removed from "arcto" commands in the output file. If these spaces do not exist in the input file, they will additionally be added to the output file, which is the opposite of the expected behaviour of noSpaceAfterFlags.

To Reproduce
Steps to reproduce the behavior:

  1. Save this file (adapted from a MDN path example) and change the extension to .SVG, or copy & save this text as a SVG file:
<svg viewBox="0 0 325 325" xmlns="http://www.w3.org/2000/svg"><path d="M80 80a45 45 0 0045 45V80z" fill="green"/><path d="M230 80a45 45 0 1045 45V80z" fill="red"/><path d="M80 230a45 45 0 0145 45v-45z" fill="purple"/><path d="M230 230a45 45 0 1145 45v-45z" fill="#00f"/></svg>

(GitHub doesn't let me upload SVGs :/)
2. Save this file and change the extension to .JS, or copy & save this text as a javascript file:

const { extendDefaultPlugins } = require('svgo');
module.exports = {
  plugins: extendDefaultPlugins([
    {
      name: 'convertPathData',
      active: true,
      params: {
        noSpaceAfterFlags: true
      }
    },
    {
      name: 'mergePaths',
      active: true,
      params: {
        noSpaceAfterFlags: true
      }
    }
  ])
}

(GitHub doesn't let me upload javascript files either :/)
3. Run SVGO 2.2.0 on the provided SVG file via the command line, using the provided configuration file (--config conf.js).
4. Observe that the file size is now larger, as SVGO added extra spaces to all "arcto" commands.

Expected behavior
I have been attempting to optimise some SVG files for the web. As SVGO 2.2.0 now does not remove spaces in "arcto" commands by default (#1353), I attempted to set the configuration values to what they were previously. I noticed that when I set the parameter noSpaceAfterFlags to true in the relevant plugins, it still did not remove spaces in "arcto" commands. Regardless of what noSpaceAfterFlags was set to, it started adding them to files that did not contain them!

I'm fairly sure that #1387 is actually the cause of this bug: js2path previously called the method cleanupOutData (found in tools.js) to cleanup path data, which had been removing the spaces in "arcto" commands. It looks like the PR removed this call. The new behaviour for "arcto" commands seems to be intentional (as seen here):

// elliptical arc large-arc and sweep flags are rendered with spaces

but it results in SVGO not respecting noSpaceAfterFlags.

Desktop (please complete the following information):

  • SVGO Version: 2.2.0 (the bug was introduced in 2.2.0)
  • NodeJs Version: 7.6.0
  • OS: MacOS Mojave
@TrySound
Copy link
Member

TrySound commented Mar 6, 2021

Fixed in v2.2.1

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

No branches or pull requests

2 participants