Potential fix for urls in content surrounded with gunk

This commit is contained in:
Nikola Lukovic 2023-10-19 18:07:51 +02:00
parent dfce5fe748
commit 3725943ecf
No known key found for this signature in database
GPG Key ID: E732B8290767CE3B
2 changed files with 10 additions and 4 deletions

View File

@ -39,7 +39,7 @@ import { hookForDev } from '../../lib/devTools';
import { getMediaUrl as getMediaUrlDefault } from "../../lib/media"; import { getMediaUrl as getMediaUrlDefault } from "../../lib/media";
import NoteImage from '../NoteImage/NoteImage'; import NoteImage from '../NoteImage/NoteImage';
import { createStore } from 'solid-js/store'; import { createStore } from 'solid-js/store';
import { linebreakRegex } from '../../constants'; import { linebreakRegex, urlExtractRegex } from '../../constants';
const specialChars = [",", "?", ";", "!", "'", ".", "-"]; const specialChars = [",", "?", ";", "!", "'", ".", "-"];
@ -81,8 +81,14 @@ const ParsedNote: Component<{
if (index > 0) { if (index > 0) {
const prefix = token.slice(0, index); const prefix = token.slice(0, index);
const url = token.slice(index);
return <>{parseToken(prefix)} {parseToken(url)}</>; const matched = token.match(urlExtractRegex)[0];
if (matched) {
const suffix = token.substring(matched.length + index, token.length);
return <>{parseToken(prefix)}{parseToken(matched)}{parseToken(suffix)}</>;
} else {
return <>{parseToken(prefix)}{parseToken(token.slice(index))}</>;
}
} }
if (!props.ignoreMedia) { if (!props.ignoreMedia) {
@ -421,7 +427,6 @@ const ParsedNote: Component<{
preview.url && preview.url &&
((!!preview.description && preview.description.length > 0) || ((!!preview.description && preview.description.length > 0) ||
!preview.images?.some(x => x === '') || !preview.images?.some(x => x === '') ||
!preview.favicons?.some(x => x === '') ||
!!preview.title !!preview.title
); );

View File

@ -245,6 +245,7 @@ export const nostrNestsRegex = /nostrnests\.com\/[a-zA-Z0-9]+/i;
export const wavlakeRegex = /https?:\/\/(?:player\.|www\.)?wavlake\.com\/(?!top|new|artists|account|activity|login|preferences|feed|profile)(?:(?:track|album)\/[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}|[a-z-]+)/i; export const wavlakeRegex = /https?:\/\/(?:player\.|www\.)?wavlake\.com\/(?!top|new|artists|account|activity|login|preferences|feed|profile)(?:(?:track|album)\/[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}|[a-z-]+)/i;
export const youtubeRegex = /(?:https?:\/\/)?(?:www|m\.)?(?:youtu\.be\/|youtube\.com\/(?:live\/|shorts\/|embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})/; export const youtubeRegex = /(?:https?:\/\/)?(?:www|m\.)?(?:youtu\.be\/|youtube\.com\/(?:live\/|shorts\/|embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})/;
export const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9\u00F0-\u02AF@:%._\+~#=]{1,256}\.[a-zA-Z0-9\u00F0-\u02AF()]{1,8}\b([-a-zA-Z0-9\u00F0-\u02AF()@:%_\+.~#?&//=]*)/; export const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9\u00F0-\u02AF@:%._\+~#=]{1,256}\.[a-zA-Z0-9\u00F0-\u02AF()]{1,8}\b([-a-zA-Z0-9\u00F0-\u02AF()@:%_\+.~#?&//=]*)/;
export const urlExtractRegex = /https?:\/\/\S+\.[^()]+(?:\([^)]*\))*/;
export const interpunctionRegex = /^(\.|,|;|\?|\!)$/; export const interpunctionRegex = /^(\.|,|;|\?|\!)$/;
export const hashtagRegex = /(?:\s|^)#[^\s!@#$%^&*(),.?":{}|<>]+/i; export const hashtagRegex = /(?:\s|^)#[^\s!@#$%^&*(),.?":{}|<>]+/i;