Skip to content

Commit 4533c64

Browse files
committed
Fix incorrect replacement for width/height/fill incorrectly removed
Closes #9
1 parent a506cf6 commit 4533c64

File tree

6 files changed

+132
-17
lines changed

6 files changed

+132
-17
lines changed

__tests__/Test.re

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ describe("simple svg", () =>
2626
readFileSync("./test/simple.svg", `utf8)->testAll
2727
);
2828

29+
describe("edge case width svg", () =>
30+
readFileSync("./test/edge-case-width.svg", `utf8)->testAll
31+
);
32+
2933
describe("clean & minimal svg", () =>
3034
readFileSync("./test/clean.svg", `utf8)->testAll
3135
);

__tests__/__snapshots__/Test.proxy.js.snap

Lines changed: 120 additions & 12 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"re:clean": "bsb -clean-world",
3131
"re:build": "bsb -make-world",
3232
"svg:format": "find test/components -name \"*.re\" | grep -v \"node_modules\" | xargs bsrefmt --in-place",
33-
"test": "yarn re:clean && yarn re:build && jest \"__tests__/(.*).proxy.js\"",
33+
"tests": "jest \"__tests__/(.*).proxy.js\"",
34+
"test": "yarn re:clean && yarn re:build && yarn tests",
3435
"release": "npmpub"
3536
},
3637
"dependencies": {

src/Transformer.re

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ let transformSvg = (svg, removeFill, removeStroke) => {
5959
// |> Js.String.replaceByRe([%re "/></g"], {j|> <|j})
6060
// remove future props
6161
|> Js.String.replaceByRe(
62-
[%re "/<svg\\s?(.*)?\\s?width=\"[^\\\"]*\"/g"],
62+
[%re "/<svg\\s?([^>]*)?\\swidth=\"[^\\\"]*\"/g"],
6363
{j|<svg \$1|j},
6464
)
6565
|> Js.String.replaceByRe(
66-
[%re "/<svg\\s?(.*)?\\s?height=\"[^\\\"]*\"/g"],
66+
[%re "/<svg\\s?([^>]*)?\\sheight=\"[^\\\"]*\"/g"],
6767
{j|<svg \$1|j},
6868
)
6969
|> Js.String.replaceByRe(
70-
[%re "/<svg\\s?(.*)?\\s?fill=\"[^\\\"]*\"/g"],
70+
[%re "/<svg\\s?([^>]*)?\\sfill=\"[^\\\"]*\"/g"],
7171
{j|<svg \$1|j},
7272
)
7373
// inject props

test/edge-case-width.svg

Lines changed: 2 additions & 0 deletions
Loading

test/simple.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)