diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-04 13:21:46 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-04 13:21:46 -0500 |
| commit | 821c7c1ded6bef400dcfda9aec27832f116ce369 (patch) | |
| tree | 00a81233e3de23213dc80f9b273d2b4569dbea4a /tests/test-wttrin--validate-weather-data.el | |
| parent | f526cf641181e9cdb533a1f8a278de1fad49ca25 (diff) | |
| download | emacs-wttrin-821c7c1ded6bef400dcfda9aec27832f116ce369.tar.gz emacs-wttrin-821c7c1ded6bef400dcfda9aec27832f116ce369.zip | |
fix: validate-weather-data corrupts match data
string-match modifies global match data as a side effect. A predicate
should not do this. Use string-match-p instead.
Diffstat (limited to 'tests/test-wttrin--validate-weather-data.el')
| -rw-r--r-- | tests/test-wttrin--validate-weather-data.el | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/test-wttrin--validate-weather-data.el b/tests/test-wttrin--validate-weather-data.el index eb03ee3..158e0e2 100644 --- a/tests/test-wttrin--validate-weather-data.el +++ b/tests/test-wttrin--validate-weather-data.el @@ -80,5 +80,16 @@ "Test that 'ERROR' at end of string causes rejection." (should-not (wttrin--validate-weather-data "Network ERROR"))) +(ert-deftest test-wttrin--validate-weather-data-boundary-does-not-corrupt-match-data () + "Validation should not clobber the caller's match data. +A predicate function should use string-match-p, not string-match." + (string-match "\\(hello\\)" "hello world") + (should (equal (match-string 1 "hello world") "hello")) + ;; Call the predicate with a string containing ERROR so the internal + ;; match actually fires — a failed match doesn't modify match data + (wttrin--validate-weather-data "ERROR: something broke") + ;; Caller's match data should be intact + (should (equal (match-string 1 "hello world") "hello"))) + (provide 'test-wttrin--validate-weather-data) ;;; test-wttrin--validate-weather-data.el ends here |
