Skip to content

Commit

Permalink
fix: remove null-byte characters (#154)
Browse files Browse the repository at this point in the history
Remove null-byte character (added when copy paste from Illustrator).

Fixes #153
  • Loading branch information
adrianhelvik authored and gregberge committed Aug 13, 2018
1 parent fa09c9b commit de7f8a7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/core/src/__snapshots__/convert.test.js.snap
Expand Up @@ -379,6 +379,24 @@ export default SvgComponent
"
`;

exports[`convert should remove null characters 1`] = `
"import React from 'react'
const SvgComponent = props => (
<svg width={25} height={25} {...props}>
<path
d=\\"M19.4 24.5H5.6c-2.8 0-5.1-2.3-5.1-5.1V5.6C.5 2.8 2.8.5 5.6.5h13.8c2.8 0 5.1 2.3 5.1 5.1v13.8c0 2.8-2.3 5.1-5.1 5.1z\\"
fill=\\"#fff\\"
stroke=\\"#434a54\\"
strokeMiterlimit={10}
/>
</svg>
)
export default SvgComponent
"
`;

exports[`convert should remove style tags 1`] = `
"import React from 'react'
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/convert.js
Expand Up @@ -9,6 +9,8 @@ async function convert(code, config = {}, state = {}) {
config = { ...DEFAULT_CONFIG, ...config }
state = expandState(state)
let result = code
// Remove null-byte character (copy/paste from Illustrator)
result = String(result).replace('\0', '')
result = await svgo(result, config, state)
result = await h2x(result, config, state)
result = await transform(result, config, state)
Expand Down
22 changes: 22 additions & 0 deletions packages/core/src/convert.test.js
Expand Up @@ -187,6 +187,27 @@ describe('convert', () => {
expect(result).toMatchSnapshot()
})

it('should remove null characters', async () => {
const result = await convert(
`<!-- Generator: Adobe Illustrator 21.1.0, SVG Export Plug-In -->
<svg version="1.1"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
x="0px" y="0px" width="25px" height="25px" viewBox="0 0 25 25" style="enable-background:new 0 0 25 25;" xml:space="preserve">
<style type="text/css">
.st0{fill:#FFFFFF;stroke:#434A54;stroke-miterlimit:10;}
</style>
<defs>
</defs>
<path class="st0" d="M19.4,24.5H5.6c-2.8,0-5.1-2.3-5.1-5.1V5.6c0-2.8,2.3-5.1,5.1-5.1h13.8c2.8,0,5.1,2.3,5.1,5.1v13.8
C24.5,22.2,22.2,24.5,19.4,24.5z"/>
</svg>
\0`
)

expect(result).toMatchSnapshot()
expect(result).not.toContain('\0')
})

describe('config', () => {
const configs = [
[{ dimensions: false }],
Expand Down Expand Up @@ -228,3 +249,4 @@ describe('convert', () => {
})
})
})

0 comments on commit de7f8a7

Please sign in to comment.