summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test-wttrin--validate-weather-data.el11
-rw-r--r--wttrin.el2
2 files changed, 12 insertions, 1 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
diff --git a/wttrin.el b/wttrin.el
index 0af5e50..d95f0c2 100644
--- a/wttrin.el
+++ b/wttrin.el
@@ -350,7 +350,7 @@ Returns the path to the saved file."
(defun wttrin--validate-weather-data (raw-string)
"Check if RAW-STRING has valid weather data.
Return t if valid, nil if missing or contains errors."
- (not (or (null raw-string) (string-match "ERROR" raw-string))))
+ (not (or (null raw-string) (string-match-p "ERROR" raw-string))))
(defun wttrin--process-weather-content (raw-string)
"Process RAW-STRING: apply ANSI filtering and remove verbose lines.