From 544117371766ab6853ec6dd45175efdc0ebd283d Mon Sep 17 00:00:00 2001
From: Dmitry Pavlov
Date: Sat, 23 Mar 2024 18:14:05 +0300
Subject: [PATCH] Properly escaping quotes in image tag attributes
Fixes #166
---
CHANGELOG.md | 14 ++++++++++++++
.../text2confl/asciidoc/block_image.html.slim | 2 +-
.../github/zeldigas/text2confl/asciidoc/helpers.rb | 4 ++++
.../text2confl/asciidoc/inline_image.html.slim | 2 +-
.../convert/asciidoc/RenderingOfImagesTest.kt | 5 +++--
.../convert/markdown/RenderingOfImagesTest.kt | 4 ++--
6 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8b3be620..b8277496 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,20 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
+### Added
+
+- Check for conflict of published page with pages parent (#142)
+
+### Changed
+
+- dependency updates:
+ - plantuml to 1.2024.3
+ - other deps (kotlin, ktor, logback, asciidoctor)
+
+### Fixed
+
+- Handling of quotes in image titles and alt text (#166)
+
## 0.16.0 - 2024-01-07
### Added
diff --git a/convert/src/main/resources/com/github/zeldigas/text2confl/asciidoc/block_image.html.slim b/convert/src/main/resources/com/github/zeldigas/text2confl/asciidoc/block_image.html.slim
index 11e0dbe4..ebee3fa2 100644
--- a/convert/src/main/resources/com/github/zeldigas/text2confl/asciidoc/block_image.html.slim
+++ b/convert/src/main/resources/com/github/zeldigas/text2confl/asciidoc/block_image.html.slim
@@ -1,6 +1,6 @@
p
= html_a_tag_if (attr? :link)
- ac:image ac:height=(attr :height) ac:width=(attr :width) ac:title=(title if title?) ac:alt=(attr :alt if attr :alt) ac:thumbnail=(attr :thumbnail) ac:align=(attr :align) ac:border=(attr :border) ac:class=(attr :class) ac:style=(attr :imgstyle) ac:vspace=(attr :vspace) ac:hspace=(attr :hspace) ac:queryparams=(attr :queryparams)
+ ac:image ac:height=(attr :height) ac:width=(attr :width) ac:title=(escape_quotes(title) if title?) ac:alt=(escape_quotes(attr :alt) if attr :alt) ac:thumbnail=(attr :thumbnail) ac:align=(attr :align) ac:border=(attr :border) ac:class=(attr :class) ac:style=(attr :imgstyle) ac:vspace=(attr :vspace) ac:hspace=(attr :hspace) ac:queryparams=(escape_quotes(attr :queryparams) if attr :queryparams)
- if uriish? attr :target
ri:url ri:value=(attr :target) /
- else
diff --git a/convert/src/main/resources/com/github/zeldigas/text2confl/asciidoc/helpers.rb b/convert/src/main/resources/com/github/zeldigas/text2confl/asciidoc/helpers.rb
index 480f6ceb..83d6836e 100644
--- a/convert/src/main/resources/com/github/zeldigas/text2confl/asciidoc/helpers.rb
+++ b/convert/src/main/resources/com/github/zeldigas/text2confl/asciidoc/helpers.rb
@@ -287,5 +287,9 @@ def adjusted_paragraph_content
content.gsub(Asciidoctor::LF, ' ')
end
+ def escape_quotes val
+ val.gsub(/"/, '"'.freeze)
+ end
+
end
diff --git a/convert/src/main/resources/com/github/zeldigas/text2confl/asciidoc/inline_image.html.slim b/convert/src/main/resources/com/github/zeldigas/text2confl/asciidoc/inline_image.html.slim
index 8136a349..5d886a70 100644
--- a/convert/src/main/resources/com/github/zeldigas/text2confl/asciidoc/inline_image.html.slim
+++ b/convert/src/main/resources/com/github/zeldigas/text2confl/asciidoc/inline_image.html.slim
@@ -1,5 +1,5 @@
= html_a_tag_if (attr? :link)
- ac:image ac:height=(attr :height) ac:width=(attr :width) ac:title=(attr :title if attr? :title) ac:alt=(attr :alt if attr :alt) ac:thumbnail=(attr :thumbnail) ac:align=(attr :align) ac:border=(attr :border) ac:class=(attr :class) ac:style=(attr :imgstyle) ac:vspace=(attr :vspace) ac:hspace=(attr :hspace) ac:queryparams=(attr :queryparams)
+ ac:image ac:height=(attr :height) ac:width=(attr :width) ac:title=(escape_quotes(attr :title) if attr? :title) ac:alt=(escape_quotes(attr :alt) if attr :alt) ac:thumbnail=(attr :thumbnail) ac:align=(attr :align) ac:border=(attr :border) ac:class=(attr :class) ac:style=(attr :imgstyle) ac:vspace=(attr :vspace) ac:hspace=(attr :hspace) ac:queryparams=(escape_quotes(attr :queryparams) if attr :queryparams)
- if uriish? target
ri:url ri:value=(target) /
- else
diff --git a/convert/src/test/kotlin/com/github/zeldigas/text2confl/convert/asciidoc/RenderingOfImagesTest.kt b/convert/src/test/kotlin/com/github/zeldigas/text2confl/convert/asciidoc/RenderingOfImagesTest.kt
index 69d89583..66ce723e 100644
--- a/convert/src/test/kotlin/com/github/zeldigas/text2confl/convert/asciidoc/RenderingOfImagesTest.kt
+++ b/convert/src/test/kotlin/com/github/zeldigas/text2confl/convert/asciidoc/RenderingOfImagesTest.kt
@@ -18,7 +18,8 @@ internal class RenderingOfImagesTest : RenderingTestBase() {
image::assets/image.jpg[]
- .Asset
+ [#img_custom_id]
+ ."Quoted text" regular text
image::assets/image.jpg[Alt]
""".trimIndent(),
attachments = mapOf(
@@ -35,7 +36,7 @@ internal class RenderingOfImagesTest : RenderingTestBase() {
Figure 1. A Title
-
Figure 2. Asset
+
Figure 2. "Quoted text" regular text <special text>
""".trimIndent(),
)
}
diff --git a/convert/src/test/kotlin/com/github/zeldigas/text2confl/convert/markdown/RenderingOfImagesTest.kt b/convert/src/test/kotlin/com/github/zeldigas/text2confl/convert/markdown/RenderingOfImagesTest.kt
index 5c248765..094ae3eb 100644
--- a/convert/src/test/kotlin/com/github/zeldigas/text2confl/convert/markdown/RenderingOfImagesTest.kt
+++ b/convert/src/test/kotlin/com/github/zeldigas/text2confl/convert/markdown/RenderingOfImagesTest.kt
@@ -17,7 +17,7 @@ internal class RenderingOfImagesTest : RenderingTestBase() {
![](assets/image.jpg)
- ![Alt](assets/image.jpg "Asset")
+ ![Alt text with "quotes"](assets/image.jpg "Asset")
""".trimIndent(),
attachments = mapOf(
"assets/image.jpg" to Attachment(
@@ -33,7 +33,7 @@ internal class RenderingOfImagesTest : RenderingTestBase() {
-
+
""".trimIndent(),
)
}