File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed
Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ export default {
6464 title = ' '
6565 })
6666 } else {
67- url = result .url
67+ url = this . findUrl ( result .url )
6868 title = ' '
6969 }
7070
@@ -95,6 +95,32 @@ export default {
9595 }
9696 })
9797 return true
98+ },
99+ /**
100+ * Check that the supplied string is a valid URL. If not, look for a
101+ * URL at the end of the string, to match the input we see from the
102+ * Share action in some apps.
103+ */
104+ findUrl (url ) {
105+ try {
106+ // If we can parse this string as a URL, we are done.
107+ // eslint-disable-next-line no-new
108+ new URL (url)
109+ return url
110+ } catch (e1) {
111+ // If not, see whether we can find a URL at the end of this string.
112+ // This happens when we share from the Amazon Shopping app.
113+ const lastWord = url .trim ().split (' ' ).slice (- 1 )[0 ]
114+ try {
115+ // eslint-disable-next-line no-new
116+ new URL (lastWord)
117+ // The last word is a URL - return it
118+ return lastWord
119+ } catch (e2) {
120+ // We didn't find a valid URL - return our input unchanged
121+ return url
122+ }
123+ }
98124 }
99125 }
100126}
You can’t perform that action at this time.
0 commit comments