Skip to content

Commit de7f8a7

Browse files
adrianhelvikgregberge
authored andcommitted
fix: remove null-byte characters (#154)
Remove null-byte character (added when copy paste from Illustrator). Fixes #153
1 parent fa09c9b commit de7f8a7

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

packages/core/src/__snapshots__/convert.test.js.snap

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,24 @@ export default SvgComponent
379379
"
380380
`;
381381

382+
exports[`convert should remove null characters 1`] = `
383+
"import React from 'react'
384+
385+
const SvgComponent = props => (
386+
<svg width={25} height={25} {...props}>
387+
<path
388+
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\\"
389+
fill=\\"#fff\\"
390+
stroke=\\"#434a54\\"
391+
strokeMiterlimit={10}
392+
/>
393+
</svg>
394+
)
395+
396+
export default SvgComponent
397+
"
398+
`;
399+
382400
exports[`convert should remove style tags 1`] = `
383401
"import React from 'react'
384402

packages/core/src/convert.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ async function convert(code, config = {}, state = {}) {
99
config = { ...DEFAULT_CONFIG, ...config }
1010
state = expandState(state)
1111
let result = code
12+
// Remove null-byte character (copy/paste from Illustrator)
13+
result = String(result).replace('\0', '')
1214
result = await svgo(result, config, state)
1315
result = await h2x(result, config, state)
1416
result = await transform(result, config, state)

packages/core/src/convert.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,27 @@ describe('convert', () => {
187187
expect(result).toMatchSnapshot()
188188
})
189189

190+
it('should remove null characters', async () => {
191+
const result = await convert(
192+
`<!-- Generator: Adobe Illustrator 21.1.0, SVG Export Plug-In -->
193+
<svg version="1.1"
194+
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
195+
x="0px" y="0px" width="25px" height="25px" viewBox="0 0 25 25" style="enable-background:new 0 0 25 25;" xml:space="preserve">
196+
<style type="text/css">
197+
.st0{fill:#FFFFFF;stroke:#434A54;stroke-miterlimit:10;}
198+
</style>
199+
<defs>
200+
</defs>
201+
<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
202+
C24.5,22.2,22.2,24.5,19.4,24.5z"/>
203+
</svg>
204+
\0`
205+
)
206+
207+
expect(result).toMatchSnapshot()
208+
expect(result).not.toContain('\0')
209+
})
210+
190211
describe('config', () => {
191212
const configs = [
192213
[{ dimensions: false }],
@@ -228,3 +249,4 @@ describe('convert', () => {
228249
})
229250
})
230251
})
252+

0 commit comments

Comments
 (0)