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

Remove null-byte characters. Fixes #153 #154

Merged
merged 3 commits into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/core/src/__snapshots__/convert.test.js.snap
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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', () => {
})
})
})