From 2ea5c6bfa8101d9ec4982e404847fef1cfa9d5f0 Mon Sep 17 00:00:00 2001 From: Hernan Morales Durand <4825959+hernanmd@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:57:31 +0200 Subject: [PATCH] Fix RegexSyntaxError: no terminating "]" in SpSearchInputFieldOptionsPresenter --- ...pSearchInputFieldOptionsPresenter.class.st | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Spec2-Core/SpSearchInputFieldOptionsPresenter.class.st b/src/Spec2-Core/SpSearchInputFieldOptionsPresenter.class.st index 31171f73..3e0b6fca 100644 --- a/src/Spec2-Core/SpSearchInputFieldOptionsPresenter.class.st +++ b/src/Spec2-Core/SpSearchInputFieldOptionsPresenter.class.st @@ -97,14 +97,32 @@ SpSearchInputFieldOptionsPresenter >> regexpOptionButton [ ^ regexpOptionButton ] +{ #category : 'updating' } +SpSearchInputFieldOptionsPresenter >> safelyRegexParse: regexString ignoringCaseSearch: item [ + "Private - Avoid raising exceptions while typing regular expressions. If there is an error, we return meaning that the search did not produced any results. Example: 'test[a-c] (Do not paste it, type it) " + + ^ [ regexString asRegexIgnoringCase search: item ] + on: RegexSyntaxError + do: [ :ex | ex return: false ] +] + +{ #category : 'updating' } +SpSearchInputFieldOptionsPresenter >> safelyRegexParse: regexString search: item [ + "Private - Avoid raising exceptions while typing regular expressions. If there is an error, we return meaning that the search did not produced any results. Example: 'test[a-c] (Do not paste it, type it) " + + ^ [ regexString asRegex search: item ] + on: RegexSyntaxError + do: [ :ex | ex return: false ] +] + { #category : 'updating' } SpSearchInputFieldOptionsPresenter >> selectBlock [ "Answer a with the matching strategy depending of the active searching options in the receiver" (regexpOptionButton isActive and: [ caseCheckBox isActive ]) - ifTrue: [ ^ [ : item : regex | regex asRegex search: item ] ]. + ifTrue: [ ^ [ : item : regexString | self safelyRegexParse: regexString search: item ] ]. (regexpOptionButton isActive and: [ caseCheckBox isActive not ]) - ifTrue: [ ^ [ : item : regex | regex asRegexIgnoringCase search: item ] ]. + ifTrue: [ ^ [ : item : regexString | self safelyRegexParse: regexString ignoringCaseSearch: item ] ]. (exactOptionButton isActive and: [ caseCheckBox isActive]) ifTrue: [ ^ [ : item : pattern | item = pattern ] ].