~ chicken-core (chicken-5) 88690836207d7d4c9cc99654da8d071eaf1ba733
commit 88690836207d7d4c9cc99654da8d071eaf1ba733 Author: Peter Bex <peter.bex@xs4all.nl> AuthorDate: Tue Sep 6 21:41:44 2011 +0200 Commit: Peter Bex <peter.bex@xs4all.nl> CommitDate: Tue Sep 6 21:41:44 2011 +0200 Apply irregex fix for #687, this makes irregex-replace return the original string instead of #f when the regex did not match (upstream changeset e53cba40b988) diff --git a/irregex-core.scm b/irregex-core.scm index c4245cac..982f57e4 100644 --- a/irregex-core.scm +++ b/irregex-core.scm @@ -3791,13 +3791,13 @@ (define (irregex-replace irx str . o) (if (not (string? str)) (%irregex-error 'irregex-replace "not a string" str)) (let ((m (irregex-search irx str))) - (and - m - (string-cat-reverse - (cons (substring str (%irregex-match-end-index m 0) (string-length str)) - (append (irregex-apply-match m o) - (list (substring str 0 (%irregex-match-start-index m 0))) - )))))) + (if m + (string-cat-reverse + (cons (substring str (%irregex-match-end-index m 0) (string-length str)) + (append (irregex-apply-match m o) + (list (substring str 0 (%irregex-match-start-index m 0))) + ))) + str))) (define (irregex-replace/all irx str . o) (if (not (string? str)) (%irregex-error 'irregex-replace/all "not a string" str)) diff --git a/tests/test-irregex.scm b/tests/test-irregex.scm index 23fbcb1e..a06bc6bd 100644 --- a/tests/test-irregex.scm +++ b/tests/test-irregex.scm @@ -340,6 +340,8 @@ (test-group "utils" (test-equal "h*llo world" (irregex-replace "[aeiou]" "hello world" "*")) + (test-equal "hello world" + (irregex-replace "[xyz]" "hello world" "*")) (test-equal "h*ll* w*rld" (irregex-replace/all "[aeiou]" "hello world" "*")) (test-equal '("bob@test.com" "fred@example.com")Trap