Share extension: shared links read “www.youtube.com/watch” because the query is dropped
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
Research direction
Start with ExtractedShare.combinedContentHTML in WordPress/WordPressShareExtension/Sources/Services/ShareExtractor.swift and the proposed cases in Tests/ShareExtensionTests/ExtractedShareTests.swift. Run the ExtractedShareTests test plan cases with xcodebuild as described in the issue. Done means attribution links display only the host and bare links retain the path and query, with both tests passing.
Written by the indexing model from the issue text.
Description
Split out of #10694, which stays open for the larger ask (embedding shared content instead of linking to it).
What happens
When you share a web page to the app, the link text drops the query string. For a YouTube video, the post says "Read on www.youtube.com/watch", and that is the same for every video. The link itself (href) is correct.
There are two cases, and both read badly:
| What was shared | Link text today | Proposed |
|---|---|---|
| A page with a title or description (the "Read on …" attribution) | www.youtube.com/watch |
www.youtube.com |
| A bare link, with no title or description | www.youtube.com/watch |
www.youtube.com/watch?v=dQw4w9WgXcQ |
The "Read on" string's own translator comment gives www.site.com as its example, so the attribution should name the site. A bare link should show enough of the address to tell pages apart.
Root cause
ExtractedShare.combinedContentHTML (WordPress/WordPressShareExtension/Sources/Services/ShareExtractor.swift) builds both links with String.stringWithAnchoredLinks(). That helper always uses host + path as the link text and drops the query. The helper is a general linkifier, and its existing tests expect that behaviour, so the fix belongs in ExtractedShare, not in the helper.
Fix
In ExtractedShare.combinedContentHTML:
- Attribution: link text is
url.host. - Bare link: link text is the address without its scheme, keeping the path and query.
The share extension is the only caller of stringWithAnchoredLinks(), so the helper isn't needed here any more.
Tests
Two Swift Testing cases in a new Tests/ShareExtensionTests/ExtractedShareTests.swift. Both fail on trunk (5f78984fbd) and pass with the fix below. We ran them with xcodebuild … -testPlan WordPressUnitTests -only-testing:ShareExtensionTests/ExtractedShareTests on an iOS 27.0 simulator.
How to check on a device
- In Safari, open a YouTube video page.
- Share → Jetpack, and pick any site.
- The text should end with "— Read on www.youtube.com".
- Share the same video's URL as plain text, for example from Notes. The link should read
www.youtube.com/watch?v=….
Not checked on a device yet. The tests cover the HTML that the extension generates.
Tests
import Foundation
import Testing
struct ExtractedShareTests {
private let videoURL = URL(string: "https://www.youtube.com/watch?v=dQw4w9WgXcQ")!
/// The "Read on" attribution names the site, so its link text is the host.
@Test func attributionLinkTextIsTheHost() {
let share = makeShare(title: "Never Gonna Give You Up")
let html = share.combinedContentHTML
#expect(html.contains("Read on <a href=\"\(videoURL.absoluteString)\">www.youtube.com</a>"))
}
/// A bare shared link keeps the parts of the address that identify the page.
@Test func bareLinkTextKeepsTheQuery() {
let share = makeShare(title: "")
let html = share.combinedContentHTML
#expect(html == "<p><a href=\"\(videoURL.absoluteString)\">www.youtube.com/watch?v=dQw4w9WgXcQ</a></p>")
}
private func makeShare(title: String) -> ExtractedShare {
ExtractedShare(
title: title,
description: "",
url: videoURL,
selectedText: "",
importedText: "",
images: []
)
}
}
Fix (verified against the tests above)
@@ -25,10 +25,11 @@ struct ExtractedShare {
var readOnText = ""
if let url {
- rawLink = url.absoluteString.stringWithAnchoredLinks()
+ let address = url.absoluteString
+ rawLink = Self.anchor(href: address, text: Self.displayAddress(for: url))
let attributionText = AppLocalizedString("Read on",
comment: "In the share extension, this is the text used right before attributing a quote to a website. Example: 'Read on www.site.com'. We are looking for the 'Read on' text in this situation.")
- readOnText = "<br>— \(attributionText) \(rawLink)"
+ readOnText = "<br>— \(attributionText) \(Self.anchor(href: address, text: url.host ?? address))"
}
// Build the returned string by doing the following:
@@ -53,6 +54,18 @@ struct ExtractedShare {
return "<p>\(rawLink)</p>"
}
}
+
+ private static func anchor(href: String, text: String) -> String {
+ "<a href=\"\(href)\">\(text)</a>"
+ }
+
+ /// The address without its scheme, keeping the path and query that identify the page.
+ private static func displayAddress(for url: URL) -> String {
+ guard let scheme = url.scheme else {
+ return url.absoluteString
+ }
+ return String(url.absoluteString.dropFirst(scheme.count + "://".count))
+ }
}
struct ExtractedImage {
- Dominant language
- Swift
- Stars
- 3.9k
- Forks
- 1.2k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 97
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from wordpress-mobile/WordPress-iOS
-
[Pri] Low [Status] Ready for Dev [Type] Bug /Me
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
wordpress-mobile/WordPress-iOS#26279 · 1 comment ·
Maintainers usually reply within 1 day
-
[Pri] Low [Status] Ready for Dev [Type] Bug Blogging Prompts Notifications
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
wordpress-mobile/WordPress-iOS#26256 · 1 comment ·
Maintainers usually reply within 1 day
-
[Status] Ready for Dev [Type] Bug Reader
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
wordpress-mobile/WordPress-iOS#26254 · 2 comments ·
Maintainers usually reply within 1 day
-
[Type] Bug Posts + Pages UI
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
wordpress-mobile/WordPress-iOS#26232 · 1 comment ·
Maintainers usually reply within 1 day
-
[Type] Tech Debt Site Creation
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
wordpress-mobile/WordPress-iOS#26113 · 3 comments ·
Maintainers usually reply within 1 day
All issues in wordpress-mobile/WordPress-iOS
Similar issues
-
needs-triage S3: minor
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
manaflow-ai/cmux#28422 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
SwiftOldDriver/iOS-Weekly#5480 ·
-
Seed a JRNYAx price before the last close so asset-detail S1.3 doesn't fail from 08:00Z to the openOpenbug tests
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
lognorman20/monaco#7231 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 5 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 7 days