From 06b30f92e83cdd968bdb2772530b78b8bb0f0a3f Mon Sep 17 00:00:00 2001
From: NFSL2001 <33471049+NightFurySL2001@users.noreply.github.com>
Date: Mon, 8 May 2023 19:29:43 +0800
Subject: [PATCH 1/8] Allow more SVG text in allowText option
---
src/picosvg/svg.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/picosvg/svg.py b/src/picosvg/svg.py
index 1b7ce56..5accc92 100644
--- a/src/picosvg/svg.py
+++ b/src/picosvg/svg.py
@@ -1,6 +1,6 @@
# Copyright 2020 Google LLC
#
-# Licensed under the Apache License, Version 2.0 (the "License");
+# Licensed under the Apache License, Version 2.0 (the "License");/text[0]
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@@ -1303,7 +1303,7 @@ def checkpicosvg(self, allow_text=False):
r"^/svg\[0\](/(path|g)\[\d+\])+$",
}
if allow_text:
- path_allowlist.add(r"^/svg\[0\](/text\[\d+\])+$")
+ path_allowlist.add(r"^/svg\[0\](/(text|tspan|textPath)\[\d+\])+$")
paths_required = {
"/svg[0]",
"/svg[0]/defs[0]",
From 8e3de3d3fd4ae12cb7ff0af7bf714128a8897762 Mon Sep 17 00:00:00 2001
From: NFSL2001 <33471049+NightFurySL2001@users.noreply.github.com>
Date: Mon, 8 May 2023 19:32:46 +0800
Subject: [PATCH 2/8] whoopsie
---
src/picosvg/svg.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/picosvg/svg.py b/src/picosvg/svg.py
index 5accc92..c418065 100644
--- a/src/picosvg/svg.py
+++ b/src/picosvg/svg.py
@@ -1,6 +1,6 @@
# Copyright 2020 Google LLC
#
-# Licensed under the Apache License, Version 2.0 (the "License");/text[0]
+# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
From 75646e605309e6d3bcded085f69b549f299e87c2 Mon Sep 17 00:00:00 2001
From: NFSL2001 <33471049+NightFurySL2001@users.noreply.github.com>
Date: Wed, 10 May 2023 21:07:50 +0800
Subject: [PATCH 3/8] Update svg_test.py for tspan and textPath
---
tests/svg_test.py | 72 ++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 68 insertions(+), 4 deletions(-)
diff --git a/tests/svg_test.py b/tests/svg_test.py
index 898cc52..003ceb3 100644
--- a/tests/svg_test.py
+++ b/tests/svg_test.py
@@ -675,14 +675,78 @@ def test_remove_processing_instructions():
assert "xpacket" not in pico_svg.tostring()
-def test_allow_text():
- text_svg = load_test_svg("text-before.svg")
+@pytest.mark.parametrize(
+ "svg_string, match_re, expected_passthrough",
+ [
+ # text element
+ (
+ """
+
+ """,
+ r"Unable to convert to picosvg: BadElement: /svg\[0\]/text\[0\]",
+ "text",
+ ),
+ # text with tspan
+ (
+ """
+
+ """,
+ r"Unable to convert to picosvg: BadElement: /svg\[0\]/text\[0\]",
+ "tspan",
+ ),
+ # tspan without text
+ (
+ """
+
+ """,
+ r"Unable to convert to picosvg: BadElement: /svg\[0\]/tspan\[0\]",
+ "tspan",
+ ),
+ # text with textPath, sample copied from https://developer.mozilla.org/en-US/docs/Web/SVG/Element/textPath
+ (
+ """
+
+ """,
+ r"Unable to convert to picosvg: BadElement: /svg\[0\]/text\[0\]",
+ "textPath",
+ ),
+ ],
+)
+def test_allow_text(svg_string, match_re, expected_passthrough):
+ text_svg = SVG.fromstring(svg_string)
with pytest.raises(
ValueError,
- match=r"Unable to convert to picosvg: BadElement: /svg\[0\]/text\[0\]",
+ match=match_re,
):
text_svg.topicosvg()
- assert "text" in text_svg.topicosvg(allow_text=True).tostring()
+ assert expected_passthrough in text_svg.topicosvg(allow_text=True).tostring()
def test_bounding_box():
From 9b1ab292029d398eeba8b545253c6784facdfe6a Mon Sep 17 00:00:00 2001
From: NFSL2001 <33471049+NightFurySL2001@users.noreply.github.com>
Date: Wed, 10 May 2023 21:08:11 +0800
Subject: [PATCH 4/8] Delete text-before.svg
---
tests/text-before.svg | 5 -----
1 file changed, 5 deletions(-)
delete mode 100644 tests/text-before.svg
diff --git a/tests/text-before.svg b/tests/text-before.svg
deleted file mode 100644
index 390a696..0000000
--- a/tests/text-before.svg
+++ /dev/null
@@ -1,5 +0,0 @@
-
From 4bcb5aa38272a06ccc0b2e40ee20ccd19e5fce55 Mon Sep 17 00:00:00 2001
From: NFSL2001 <33471049+NightFurySL2001@users.noreply.github.com>
Date: Thu, 11 May 2023 18:11:13 +0800
Subject: [PATCH 5/8] tspan only in text or textpath
---
src/picosvg/svg.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/picosvg/svg.py b/src/picosvg/svg.py
index c418065..88c160a 100644
--- a/src/picosvg/svg.py
+++ b/src/picosvg/svg.py
@@ -1303,7 +1303,7 @@ def checkpicosvg(self, allow_text=False):
r"^/svg\[0\](/(path|g)\[\d+\])+$",
}
if allow_text:
- path_allowlist.add(r"^/svg\[0\](/(text|tspan|textPath)\[\d+\])+$")
+ path_allowlist.add(r"^/svg\[0\](/(text|textPath)\[\d+\])+(/(text|tspan|textPath)\[\d+\])+$")
paths_required = {
"/svg[0]",
"/svg[0]/defs[0]",
From 74f0fd20733e2f90a533fadacb47c0c1ad64fbfe Mon Sep 17 00:00:00 2001
From: NFSL2001 <33471049+NightFurySL2001@users.noreply.github.com>
Date: Thu, 11 May 2023 18:15:56 +0800
Subject: [PATCH 6/8] Update svg_test.py
---
tests/svg_test.py | 12 ------------
1 file changed, 12 deletions(-)
diff --git a/tests/svg_test.py b/tests/svg_test.py
index 003ceb3..a175843 100644
--- a/tests/svg_test.py
+++ b/tests/svg_test.py
@@ -704,18 +704,6 @@ def test_remove_processing_instructions():
r"Unable to convert to picosvg: BadElement: /svg\[0\]/text\[0\]",
"tspan",
),
- # tspan without text
- (
- """
-
- """,
- r"Unable to convert to picosvg: BadElement: /svg\[0\]/tspan\[0\]",
- "tspan",
- ),
# text with textPath, sample copied from https://developer.mozilla.org/en-US/docs/Web/SVG/Element/textPath
(
"""
From 2d753fdfa7922839a8e8b81b57e112529a7c7dea Mon Sep 17 00:00:00 2001
From: NFSL2001 <33471049+NightFurySL2001@users.noreply.github.com>
Date: Thu, 11 May 2023 18:24:03 +0800
Subject: [PATCH 7/8] Update svg.py
---
src/picosvg/svg.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/picosvg/svg.py b/src/picosvg/svg.py
index 88c160a..e5f5815 100644
--- a/src/picosvg/svg.py
+++ b/src/picosvg/svg.py
@@ -1303,7 +1303,9 @@ def checkpicosvg(self, allow_text=False):
r"^/svg\[0\](/(path|g)\[\d+\])+$",
}
if allow_text:
- path_allowlist.add(r"^/svg\[0\](/(text|textPath)\[\d+\])+(/(text|tspan|textPath)\[\d+\])+$")
+ path_allowlist.add(
+ r"^/svg\[0\](/(text|textPath)\[\d+\])+(/(text|tspan|textPath)\[\d+\])+$"
+ )
paths_required = {
"/svg[0]",
"/svg[0]/defs[0]",
From 5b93fe8c1158562132b02554935e6de88b208689 Mon Sep 17 00:00:00 2001
From: NFSL2001 <33471049+NightFurySL2001@users.noreply.github.com>
Date: Fri, 12 May 2023 17:34:10 +0800
Subject: [PATCH 8/8] allow 0 inner text element
---
src/picosvg/svg.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/picosvg/svg.py b/src/picosvg/svg.py
index e5f5815..6abb6f9 100644
--- a/src/picosvg/svg.py
+++ b/src/picosvg/svg.py
@@ -1304,7 +1304,7 @@ def checkpicosvg(self, allow_text=False):
}
if allow_text:
path_allowlist.add(
- r"^/svg\[0\](/(text|textPath)\[\d+\])+(/(text|tspan|textPath)\[\d+\])+$"
+ r"^/svg\[0\](/(text|textPath)\[\d+\])+(/(text|tspan|textPath)\[\d+\])*$"
)
paths_required = {
"/svg[0]",