Skip to content

Commit b9edb2f

Browse files
Trim whitespace from URL input (#1172)
1 parent ded7b7b commit b9edb2f

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

frontend/src/components/urlInput/urlInput.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ const URLInput: FC<URLInputProps> = ({ lens, type, errors }) => {
5656
);
5757

5858
const handleAdd = () => {
59-
if (!newURL || !selectedSite) return;
60-
const cleanedURL = cleanURL(selectedSite?.regex, newURL);
59+
const trimmedURL = newURL.trim();
60+
if (!trimmedURL || !selectedSite) return;
61+
const cleanedURL = cleanURL(selectedSite?.regex, trimmedURL);
6162

62-
const url = cleanedURL ?? newURL;
63+
const url = cleanedURL ?? trimmedURL;
6364
if (!urls.some((u) => u.url === url))
6465
append({
6566
url,
@@ -72,9 +73,12 @@ const URLInput: FC<URLInputProps> = ({ lens, type, errors }) => {
7273
setNewURL("");
7374
};
7475

75-
const handleInput = (url: string) => {
76+
const handleInput = (rawURL: string) => {
7677
if (!inputRef.current || !selectRef.current) return;
7778

79+
const url = rawURL.trim();
80+
if (url !== rawURL) inputRef.current.value = url;
81+
7882
const site = sites.find((s) => s.regex && new RegExp(s.regex).test(url));
7983

8084
if (site && selectedSite?.id !== site.id) {

0 commit comments

Comments
 (0)