Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Share extension: shared links read “www.youtube.com/watch” because the query is dropped

Open Beginner friendly
#26,276 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
ios, swift
Domain
frontend, mobile

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

[Pri] Low [Status] Ready for Dev [Type] Bug Share Extension

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

  1. In Safari, open a YouTube video page.
  2. Share → Jetpack, and pick any site.
  3. The text should end with "— Read on www.youtube.com".
  4. 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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from wordpress-mobile/WordPress-iOS

All issues in wordpress-mobile/WordPress-iOS

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.