fix URL parsing edge cases (#360)

This should fix the following:
- URLs in parentheses
- URLs at the end of a sentence
This commit is contained in:
Sam Samskies
2023-02-27 09:21:38 -10:00
committed by GitHub
parent f934dcd092
commit 2782f24690
4 changed files with 50 additions and 10 deletions

View File

@ -0,0 +1,40 @@
import { splitByUrl } from "./Util";
describe("splitByUrl", () => {
it("should split a string by URLs", () => {
const inputStr =
"@npub1q6mcr8t not https://example.com- sure what your stack is, https://example.com but I made a https://example.com! simple example (https://example.com) of how https://example.com/yo-yo https://example.example.com to do this https://example.com, https://example.com?q=asdf for Next.js apps hosted on Vercel https://example.com. Scarcity in money provides the incentive to create abundance in other things as there is a mechanism to reliably store value. https://i.imgur.com/rkqhjeq.png Every form of money that could be inflated by way of force or technological advancement has been.";
const expectedOutput = [
"@npub1q6mcr8t not ",
"https://example.com-",
" sure what your stack is, ",
"https://example.com",
" but I made a ",
"https://example.com",
"! simple example (",
"https://example.com",
") of how ",
"https://example.com/yo-yo",
" ",
"https://example.example.com",
" to do this ",
"https://example.com",
", ",
"https://example.com?q=asdf",
" for Next.js apps hosted on Vercel ",
"https://example.com",
". Scarcity in money provides the incentive to create abundance in other things as there is a mechanism to reliably store value. ",
"https://i.imgur.com/rkqhjeq.png",
" Every form of money that could be inflated by way of force or technological advancement has been.",
];
expect(splitByUrl(inputStr)).toEqual(expectedOutput);
});
it("should return an array with a single string if no URLs are found", () => {
const inputStr = "This is a regular string with no URLs";
const expectedOutput = ["This is a regular string with no URLs"];
expect(splitByUrl(inputStr)).toEqual(expectedOutput);
});
});