Skip to content

Commit

Permalink
Fix RegexSyntaxError: no terminating "]" in SpSearchInputFieldOptions…
Browse files Browse the repository at this point in the history
…Presenter
  • Loading branch information
hernanmd committed Oct 25, 2024
1 parent 4abd4fa commit 2ea5c6b
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/Spec2-Core/SpSearchInputFieldOptionsPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 <false> 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 <false> 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 <BlockClosure> 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 ] ].
Expand Down

0 comments on commit 2ea5c6b

Please sign in to comment.