From 7d9c1f3f3096f72033adc18c8250415e3d89dfad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gu=CC=88nther?= Date: Thu, 26 Sep 2024 15:35:14 +0200 Subject: [PATCH 1/5] BUGFIX: Trim leading and tailing whitespaces Whitespaces like a tab can lead to a 404 error if a URL has been pasted to a LinkEditor or LinkInput. As datasources, assets, URLs and slugs should not start with a whitespace, we can remove them. Fixes: #3859 --- packages/neos-ui-editors/src/Library/LinkInput.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/neos-ui-editors/src/Library/LinkInput.js b/packages/neos-ui-editors/src/Library/LinkInput.js index af590598d6..abad8084cc 100644 --- a/packages/neos-ui-editors/src/Library/LinkInput.js +++ b/packages/neos-ui-editors/src/Library/LinkInput.js @@ -149,6 +149,10 @@ export default class LinkInput extends PureComponent { } handleSearchTermChange = searchTerm => { + // trim leading and trailing whitespace as it can cause issues + // with the further processing + searchTerm.trim() + this.setState({searchTerm}); if (isUriOrInternalLink(searchTerm)) { From 9e59a3c6eeb4fee87ca4afe19106203f4f1c7f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gu=CC=88nther?= Date: Thu, 26 Sep 2024 15:59:06 +0200 Subject: [PATCH 2/5] BUGFIX: Prevent potential js error Ensure that searchTerm is a string before trimming the value. --- packages/neos-ui-editors/src/Library/LinkInput.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/neos-ui-editors/src/Library/LinkInput.js b/packages/neos-ui-editors/src/Library/LinkInput.js index abad8084cc..af8d649d39 100644 --- a/packages/neos-ui-editors/src/Library/LinkInput.js +++ b/packages/neos-ui-editors/src/Library/LinkInput.js @@ -151,7 +151,9 @@ export default class LinkInput extends PureComponent { handleSearchTermChange = searchTerm => { // trim leading and trailing whitespace as it can cause issues // with the further processing - searchTerm.trim() + if (typeof searchTerm === 'string') { + searchTerm.trim() + } this.setState({searchTerm}); From a53f256115fcb39dc3b68b26f3e601407e147f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gu=CC=88nther?= Date: Tue, 8 Oct 2024 13:36:01 +0200 Subject: [PATCH 3/5] TASK: Assign trimmed value to the searchTerm --- packages/neos-ui-editors/src/Library/LinkInput.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/neos-ui-editors/src/Library/LinkInput.js b/packages/neos-ui-editors/src/Library/LinkInput.js index af8d649d39..8447dca3ad 100644 --- a/packages/neos-ui-editors/src/Library/LinkInput.js +++ b/packages/neos-ui-editors/src/Library/LinkInput.js @@ -152,7 +152,7 @@ export default class LinkInput extends PureComponent { // trim leading and trailing whitespace as it can cause issues // with the further processing if (typeof searchTerm === 'string') { - searchTerm.trim() + searchTerm = searchTerm.trim() } this.setState({searchTerm}); From 41fb986a86f38f47e6ba22180f00d2ec37a534cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gu=CC=88nther?= Date: Tue, 8 Oct 2024 15:02:22 +0200 Subject: [PATCH 4/5] TASK: just trim the leading part of a string --- packages/neos-ui-editors/src/Library/LinkInput.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/neos-ui-editors/src/Library/LinkInput.js b/packages/neos-ui-editors/src/Library/LinkInput.js index 8447dca3ad..525fad7381 100644 --- a/packages/neos-ui-editors/src/Library/LinkInput.js +++ b/packages/neos-ui-editors/src/Library/LinkInput.js @@ -149,10 +149,10 @@ export default class LinkInput extends PureComponent { } handleSearchTermChange = searchTerm => { - // trim leading and trailing whitespace as it can cause issues + // trim leading whitespace as it can cause issues // with the further processing if (typeof searchTerm === 'string') { - searchTerm = searchTerm.trim() + searchTerm = searchTerm.trimStart(); } this.setState({searchTerm}); From 500f9504874988181c105a37f684bfbd99d7d449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gu=CC=88nther?= Date: Tue, 8 Oct 2024 15:30:04 +0200 Subject: [PATCH 5/5] TASK: Trim search term on manuall apply for --- packages/neos-ui-editors/src/Library/LinkInput.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/neos-ui-editors/src/Library/LinkInput.js b/packages/neos-ui-editors/src/Library/LinkInput.js index 525fad7381..18d5c2a58a 100644 --- a/packages/neos-ui-editors/src/Library/LinkInput.js +++ b/packages/neos-ui-editors/src/Library/LinkInput.js @@ -275,9 +275,16 @@ export default class LinkInput extends PureComponent { } handleManualSetLink = () => { - this.props.onLinkChange(this.state.searchTerm); + let {searchTerm} = this.state; + // trim tailing whitespace as it can cause issues + if (typeof searchTerm === 'string') { + searchTerm = searchTerm.trim(); + this.setState({searchTerm}); + } + + this.props.onLinkChange(searchTerm); this.setState({ - isEditMode: !this.state.searchTerm + isEditMode: !searchTerm }); }