Skip to content

Commit 6ab7dc3

Browse files
committed
fix(Home#checkForIntent): Better findUrl algorithm
fixes #1741 Signed-off-by: Marcel Klehr <[email protected]>
1 parent 500fc59 commit 6ab7dc3

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/ui/views/native/Home.vue

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,32 @@ export default {
108108
new URL(url)
109109
return url
110110
} 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]
111+
// noop
112+
}
113+
// If not, see whether we can find a URL at the end of this string.
114+
// This happens e.g. when we share from the Amazon Shopping app.
115+
const lastWord = url.trim().split(' ').slice(-1)[0]
116+
try {
117+
// eslint-disable-next-line no-new
118+
new URL(lastWord)
119+
// The last word is a URL - return it
120+
return lastWord
121+
} catch (e2) {
122+
// noop
123+
}
124+
const indexOfHttp = url.lastIndexOf('http')
125+
if (indexOfHttp > 0) {
126+
const couldBeUrl = url.substring(indexOfHttp)
114127
try {
115128
// 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
129+
new URL(couldBeUrl)
130+
return couldBeUrl
131+
} catch (e3) {
132+
// noop
122133
}
123134
}
135+
// We didn't find a valid URL - return our input unchanged
136+
return url
124137
}
125138
}
126139
}

0 commit comments

Comments
 (0)