Skip to content

Commit

Permalink
Properly escaping quotes in image tag attributes
Browse files Browse the repository at this point in the history
Fixes #166
  • Loading branch information
zeldigas committed Mar 23, 2024
1 parent fab3069 commit 5441173
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,5 +287,9 @@ def adjusted_paragraph_content
content.gsub(Asciidoctor::LF, ' ')
end

def escape_quotes val
val.gsub(/"/, '"'.freeze)
end


end
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ internal class RenderingOfImagesTest : RenderingTestBase() {
image::assets/image.jpg[]
.Asset
[#img_custom_id]
."Quoted text" regular text <special text>
image::assets/image.jpg[Alt]
""".trimIndent(),
attachments = mapOf(
Expand All @@ -35,7 +36,7 @@ internal class RenderingOfImagesTest : RenderingTestBase() {
<p><ac:image ac:title="A Title" ac:alt="Alt text"><ri:url ri:value="https://example.org/test.jpg" /></ac:image><div class="t2c-image-title"><em>Figure 1. A Title</em></div></p>
<p><ac:image ac:alt="test"><ri:url ri:value="https://example.org/test.jpg" /></ac:image></p>
<p><ac:image ac:alt="image"><ri:attachment ri:filename="an_attachment" /></ac:image></p>
<p><ac:image ac:title="Asset" ac:alt="Alt"><ri:attachment ri:filename="an_attachment" /></ac:image><div class="t2c-image-title"><em>Figure 2. Asset</em></div></p>
<p><ac:image ac:title="&quot;Quoted text&quot; regular text &lt;special text&gt;" ac:alt="Alt"><ri:attachment ri:filename="an_attachment" /></ac:image><div class="t2c-image-title"><em>Figure 2. "Quoted text" regular text &lt;special text&gt;</em></div></p>
""".trimIndent(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -33,7 +33,7 @@ internal class RenderingOfImagesTest : RenderingTestBase() {
<p><ac:image ac:alt="Alt text" ac:title="A Title"><ri:url ri:value="https://example.org/test.jpg" /></ac:image></p>
<p><ac:image><ri:url ri:value="https://example.org/test.jpg" /></ac:image></p>
<p><ac:image><ri:attachment ri:filename="an_attachment" /></ac:image></p>
<p><ac:image ac:alt="Alt" ac:title="Asset"><ri:attachment ri:filename="an_attachment" /></ac:image></p>
<p><ac:image ac:alt="Alt text with &quot;quotes&quot;" ac:title="Asset"><ri:attachment ri:filename="an_attachment" /></ac:image></p>
""".trimIndent(),
)
}
Expand Down

0 comments on commit 5441173

Please sign in to comment.