summaryrefslogtreecommitdiff
path: root/internal/router/template_test.go
diff options
context:
space:
mode:
authorLibravatar tobi <tobi.smethurst@protonmail.com>2025-05-07 11:48:21 +0000
committerLibravatar kim <gruf@noreply.codeberg.org>2025-05-07 11:48:21 +0000
commit1f0c261fd2d3da250f62040236f7629f603f0b03 (patch)
tree19c072a3b1997a9c71e952fce659ac78e1237054 /internal/router/template_test.go
parent[chore/frontend] Put fonts in folders, update ecks pee to atkinson-hyperlegib... (diff)
downloadgotosocial-1f0c261fd2d3da250f62040236f7629f603f0b03.tar.xz
[bugfix] Fix indentation on multi-line alt text in web view (#4149)
This pull request closes https://codeberg.org/superseriousbusiness/gotosocial/issues/3403 by searching for alt or title attributes in HTML, looking for the shortest indent (if any) at the start of multiline content of said attributes, and remove that shortest indent from each line. This is a bit more fiddly than the "easy" way of doing it, but it has the advantage that it preserves user-added indents at the start of lines of alt text. Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4149 Co-authored-by: tobi <tobi.smethurst@protonmail.com> Co-committed-by: tobi <tobi.smethurst@protonmail.com>
Diffstat (limited to 'internal/router/template_test.go')
-rw-r--r--internal/router/template_test.go46
1 files changed, 40 insertions, 6 deletions
diff --git a/internal/router/template_test.go b/internal/router/template_test.go
index 19bf759e0..1c82d3ba4 100644
--- a/internal/router/template_test.go
+++ b/internal/router/template_test.go
@@ -22,10 +22,19 @@ import (
"testing"
)
-func TestOutdentPre(t *testing.T) {
+func TestOutdentPreformatted(t *testing.T) {
const html = template.HTML(`
<div class="text">
- <div class="content" lang="en">
+ <div
+ class="content"
+ lang="en"
+ title="DW from Arthur is labeled &#34;crawlers&#34;.
+
+ She&#39;s reading a sign on a door that says: &#34;robots.txt: don&#39;t crawl this website, it&#39;s not for you, please, thanks.&#34;
+
+ With her hands on her hips looking annoyed she says &#34;That sign won&#39;t stop me because I can&#39;t read!&#34;"
+ alt="pee pee poo poo"
+ >
<p>Here's a bunch of HTML, read it and weep, weep then!</p>
<pre><code class="language-html">&lt;section class=&#34;about-user&#34;&gt;
&lt;div class=&#34;col-header&#34;&gt;
@@ -67,7 +76,15 @@ func TestOutdentPre(t *testing.T) {
</div>
</div>
<div class="text">
- <div class="content" lang="en">
+ <div
+ class="content"
+ lang="en"
+ alt="DW from Arthur is labeled &#34;crawlers&#34;.
+
+ She&#39;s reading a sign on a door that says: &#34;robots.txt: don&#39;t crawl this website, it&#39;s not for you, please, thanks.&#34;
+
+ With her hands on her hips looking annoyed she says &#34;That sign won&#39;t stop me because I can&#39;t read!&#34;"
+ >
<p>Here's a bunch of HTML, read it and weep, weep then!</p>
<pre><code class="language-html">&lt;section class=&#34;about-user&#34;&gt;
&lt;div class=&#34;col-header&#34;&gt;
@@ -112,7 +129,16 @@ func TestOutdentPre(t *testing.T) {
const expected = template.HTML(`
<div class="text">
- <div class="content" lang="en">
+ <div
+ class="content"
+ lang="en"
+ title="DW from Arthur is labeled &#34;crawlers&#34;.
+
+ She&#39;s reading a sign on a door that says: &#34;robots.txt: don&#39;t crawl this website, it&#39;s not for you, please, thanks.&#34;
+
+With her hands on her hips looking annoyed she says &#34;That sign won&#39;t stop me because I can&#39;t read!&#34;"
+ alt="pee pee poo poo"
+ >
<p>Here's a bunch of HTML, read it and weep, weep then!</p>
<pre><code class="language-html">&lt;section class=&#34;about-user&#34;&gt;
&lt;div class=&#34;col-header&#34;&gt;
@@ -154,7 +180,15 @@ func TestOutdentPre(t *testing.T) {
</div>
</div>
<div class="text">
- <div class="content" lang="en">
+ <div
+ class="content"
+ lang="en"
+ alt="DW from Arthur is labeled &#34;crawlers&#34;.
+
+She&#39;s reading a sign on a door that says: &#34;robots.txt: don&#39;t crawl this website, it&#39;s not for you, please, thanks.&#34;
+
+With her hands on her hips looking annoyed she says &#34;That sign won&#39;t stop me because I can&#39;t read!&#34;"
+ >
<p>Here's a bunch of HTML, read it and weep, weep then!</p>
<pre><code class="language-html">&lt;section class=&#34;about-user&#34;&gt;
&lt;div class=&#34;col-header&#34;&gt;
@@ -197,7 +231,7 @@ func TestOutdentPre(t *testing.T) {
</div>
`)
- out := outdentPre(html)
+ out := outdentPreformatted(html)
if out != expected {
t.Fatalf("unexpected output:\n`%s`\n", out)
}