Skip to content

Commit

Permalink
Merge pull request #1830 from andybalaam/process-amazon-share-correctly
Browse files Browse the repository at this point in the history
Try to find a valid URL when an app shares title+URL stuffed together
  • Loading branch information
marcelklehr authored Jan 15, 2025
2 parents 8797eda + bd3b137 commit 3d97f82
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/ui/views/native/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default {
title = ''
})
} else {
url = result.url
url = this.findUrl(result.url)
title = ''
}
Expand Down Expand Up @@ -95,6 +95,32 @@ export default {
}
})
return true
},
/**
* Check that the supplied string is a valid URL. If not, look for a
* URL at the end of the string, to match the input we see from the
* Share action in some apps.
*/
findUrl(url) {
try {
// If we can parse this string as a URL, we are done.
// eslint-disable-next-line no-new
new URL(url)
return url
} catch (e1) {
// If not, see whether we can find a URL at the end of this string.
// This happens when we share from the Amazon Shopping app.
const lastWord = url.trim().split(' ').slice(-1)[0]
try {
// eslint-disable-next-line no-new
new URL(lastWord)
// The last word is a URL - return it
return lastWord
} catch (e2) {
// We didn't find a valid URL - return our input unchanged
return url
}
}
}
}
}
Expand Down

0 comments on commit 3d97f82

Please sign in to comment.