Skip to content

Commit 3d97f82

Browse files
authored
Merge pull request #1830 from andybalaam/process-amazon-share-correctly
Try to find a valid URL when an app shares title+URL stuffed together
2 parents 8797eda + bd3b137 commit 3d97f82

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/ui/views/native/Home.vue

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)