summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-11-13 08:44:07 +0000
committerPeter Stone <thepeterstone@gmail.com>2026-11-13 08:44:07 +0000
commit17643797517693664e6d4f5e5911b9855d6c484b (patch)
tree7d01860222cd57206599816582c18da53fae308b /app
parentfc25307e7f258b1043e1367a44a8800d03085c66 (diff)
Close the class: a caller can no longer forget where the article lives
The fix before this made site-relative images zoomable by resolving them against the article's own address. It left the parameter optional, which leaves the bug one forgetful call site away from coming back -- and coming back silently, as every image on a site-relative feed quietly refusing to zoom, which is exactly how it went unnoticed on Ftrain in the first place. It has no default now. Null is still a legitimate answer, because an article with no address genuinely cannot resolve anything, but it has to be given on purpose. A future reader surface that omits it fails to compile rather than shipping the old behaviour. Nothing about what the app does changed: the same 157 tests pass, and the six test call sites that relied on the default now say baseUrl = null, which is what they always meant. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018AwnALZL6bD4VBtATDVv3B
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/org/terst/feedreader/ui/ImageZoomLinks.kt8
-rw-r--r--app/src/test/java/org/terst/feedreader/ui/ImageZoomTest.kt14
2 files changed, 14 insertions, 8 deletions
diff --git a/app/src/main/java/org/terst/feedreader/ui/ImageZoomLinks.kt b/app/src/main/java/org/terst/feedreader/ui/ImageZoomLinks.kt
index d924c02..179955e 100644
--- a/app/src/main/java/org/terst/feedreader/ui/ImageZoomLinks.kt
+++ b/app/src/main/java/org/terst/feedreader/ui/ImageZoomLinks.kt
@@ -36,8 +36,14 @@ private val imageFileExtensions = listOf(".jpg", ".jpeg", ".png", ".gif", ".webp
* something already (ReaderExtractor's synthesized YouTube thumbnail is precisely this shape,
* and wrapping it would swallow the tap that plays the video). Those are still zoomable when
* the link points at an image file, which [zoomableImageTarget] handles on the other side.
+ *
+ * [baseUrl] is where the article itself lives, used to resolve an image address the feed wrote
+ * in shorthand. It has no default, deliberately: a caller that omits it does not silently get
+ * the behaviour that caused this bug -- every image on a site-relative feed like Ftrain's
+ * un-zoomable -- it fails to compile. Null is still a legitimate answer when there genuinely is
+ * no article address, but it has to be given on purpose rather than by forgetting.
*/
-fun linkifyImagesForZoom(html: String, baseUrl: String? = null): String = buildString {
+fun linkifyImagesForZoom(html: String, baseUrl: String?): String = buildString {
var copiedUpTo = 0
var anchorDepth = 0
for (tag in anchorOrImageTagRegex.findAll(html)) {
diff --git a/app/src/test/java/org/terst/feedreader/ui/ImageZoomTest.kt b/app/src/test/java/org/terst/feedreader/ui/ImageZoomTest.kt
index aead885..5939bf8 100644
--- a/app/src/test/java/org/terst/feedreader/ui/ImageZoomTest.kt
+++ b/app/src/test/java/org/terst/feedreader/ui/ImageZoomTest.kt
@@ -9,7 +9,7 @@ class ImageZoomTest {
@Test
fun `a bare image is wrapped in a zoom link pointing at its own source`() {
- val html = linkifyImagesForZoom("""<p>hi</p><img src="https://ex.com/a.jpg" alt="x">""")
+ val html = linkifyImagesForZoom("""<p>hi</p><img src="https://ex.com/a.jpg" alt="x">""", baseUrl = null)
assertEquals(
"""<p>hi</p><a href="feedreader-image:https://ex.com/a.jpg"><img src="https://ex.com/a.jpg" alt="x"></a>""",
html
@@ -22,18 +22,18 @@ class ImageZoomTest {
// again would swallow the tap that's supposed to play the video.
val original =
"""<a href="https://www.youtube.com/watch?v=abcdefghijk"><img src="https://i.ytimg.com/vi/x/hq720.jpg"></a>"""
- assertEquals(original, linkifyImagesForZoom(original))
+ assertEquals(original, linkifyImagesForZoom(original, baseUrl = null))
}
@Test
fun `an image after a closed link is still wrapped`() {
- val html = linkifyImagesForZoom("""<a href="https://ex.com/">t</a><img src="https://ex.com/a.png">""")
+ val html = linkifyImagesForZoom("""<a href="https://ex.com/">t</a><img src="https://ex.com/a.png">""", baseUrl = null)
assertTrue(html.endsWith("""<a href="feedreader-image:https://ex.com/a.png"><img src="https://ex.com/a.png"></a>"""))
}
@Test
fun `a protocol-relative image source becomes an https zoom target`() {
- val html = linkifyImagesForZoom("""<img src="//ex.com/a.jpg">""")
+ val html = linkifyImagesForZoom("""<img src="//ex.com/a.jpg">""", baseUrl = null)
assertEquals("""<a href="feedreader-image:https://ex.com/a.jpg"><img src="//ex.com/a.jpg"></a>""", html)
}
@@ -42,7 +42,7 @@ class ImageZoomTest {
// Relative srcs resolve against the WebView's base URL -- with no base URL to resolve
// against, better to leave the image un-zoomable than to build a dead link.
val original = """<img src="/local/a.jpg">"""
- assertEquals(original, linkifyImagesForZoom(original))
+ assertEquals(original, linkifyImagesForZoom(original, baseUrl = null))
}
@Test
@@ -80,12 +80,12 @@ class ImageZoomTest {
@Test
fun `a data uri image is left alone`() {
val original = """<img src="data:image/png;base64,AAAA">"""
- assertEquals(original, linkifyImagesForZoom(original))
+ assertEquals(original, linkifyImagesForZoom(original, baseUrl = null))
}
@Test
fun `wrapping is not confused by tags that merely start with the letter a`() {
- val html = linkifyImagesForZoom("""<abbr title="x">y</abbr><img src="https://ex.com/a.jpg">""")
+ val html = linkifyImagesForZoom("""<abbr title="x">y</abbr><img src="https://ex.com/a.jpg">""", baseUrl = null)
assertTrue(html.contains("""<a href="feedreader-image:https://ex.com/a.jpg">"""))
}