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:
40
packages/app/src/Util.test.ts
Normal file
40
packages/app/src/Util.test.ts
Normal 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);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user