Skip to content

Commit 53834b7

Browse files
committedSep 25, 2023
Fix an embarassing bug in quoteString() that resulted in some incorrect database entries, e.g. for Hebrew.
1 parent 30bc482 commit 53834b7

6 files changed

+63
-3
lines changed
 

‎datetime.el

+2-2
Original file line numberDiff line numberDiff line change
@@ -1966,7 +1966,7 @@ create based on locales `datetime' knows about.
19661966
19671967
Note that this database doesn't include timezone names. See
19681968
`datetime-timezone-name-database-version'."
1969-
5)
1969+
6)
19701970

19711971
(defun datetime-timezone-database-version ()
19721972
"Return timezone database version, a simple integer.
@@ -1989,7 +1989,7 @@ Other locale-specific data as well as locale-independent data
19891989
about timezones is contained in different databases. See
19901990
`datetime-locale-database-version' and
19911991
`datetime-timezone-database-version'."
1992-
4)
1992+
5)
19931993

19941994

19951995
(provide 'datetime)

‎dev/HarvestData.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.time.zone.*;
66
import java.util.*;
77
import java.util.function.*;
8+
import java.util.regex.*;
89
import java.util.stream.*;
910

1011

@@ -606,9 +607,12 @@ protected static Map <String, String> toPatternPlist (Function <FormatStyle, Str
606607
return patterns;
607608
}
608609

610+
private static final String ESCAPED_BACKSLASH = Matcher.quoteReplacement ("\\\\");
611+
private static final String ESCAPED_DOUBLE_QUOTE = Matcher.quoteReplacement ("\\\"");
612+
609613
protected static String quoteString (String string)
610614
{
611-
return string != null ? String.format ("\"%s\"", string.replaceAll ("\\\\", "\\\\").replaceAll ("\"", "\\\"")) : "nil";
615+
return string != null ? String.format ("\"%s\"", string.replaceAll ("\\\\", ESCAPED_BACKSLASH).replaceAll ("\"", ESCAPED_DOUBLE_QUOTE)) : "nil";
612616
}
613617

614618

‎locale-data.extmap

-2 Bytes
Binary file not shown.

‎test/base.el

+50
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,54 @@
128128
(error (format "[failed to retrieve: %S]" error))))))))))
129129

130130

131+
(ert-deftest datetime-locale-database-sanity ()
132+
(dolist (locale (datetime-list-locales t))
133+
(let ((decimal-separator (datetime-locale-field locale :decimal-separator))
134+
(eras (datetime-locale-field locale :eras))
135+
(month-context-abbr (datetime-locale-field locale :month-context-abbr))
136+
(month-context-names (datetime-locale-field locale :month-context-names))
137+
(weekday-context-abbr (datetime-locale-field locale :weekday-context-abbr))
138+
(weekday-context-names (datetime-locale-field locale :weekday-context-names))
139+
(month-standalone-abbr (datetime-locale-field locale :month-standalone-abbr))
140+
(month-standalone-names (datetime-locale-field locale :month-standalone-names))
141+
(weekday-standalone-abbr (datetime-locale-field locale :weekday-standalone-abbr))
142+
(weekday-standalone-names (datetime-locale-field locale :weekday-standalone-names))
143+
(am-pm (datetime-locale-field locale :am-pm)))
144+
(ert-info ((format "\
145+
locale = %S
146+
decimal-separator = %S
147+
eras = %S
148+
month-context-abbr = %S
149+
month-context-names = %S
150+
weekday-context-abbr = %S
151+
weekday-context-names = %S
152+
month-standalone-abbr = %S
153+
month-standalone-names = %S
154+
weekday-standalone-abbr = %S
155+
weekday-standalone-names = %S
156+
am-pm = %S"
157+
locale decimal-separator eras
158+
month-context-abbr month-context-names
159+
weekday-context-abbr weekday-context-names
160+
month-standalone-abbr month-standalone-names
161+
weekday-standalone-abbr weekday-standalone-names
162+
am-pm))
163+
(should (memq decimal-separator '(?. ?, )))
164+
(dolist (entry `((,eras 2)
165+
(,month-context-abbr 12)
166+
(,month-context-names 12)
167+
(,weekday-context-abbr 7)
168+
(,weekday-context-names 7)
169+
(,month-standalone-abbr 12)
170+
(,month-standalone-names 12)
171+
(,weekday-standalone-abbr 7)
172+
(,weekday-standalone-names 7)
173+
(,am-pm 2)))
174+
(let ((value (car entry))
175+
(length (cadr entry)))
176+
(should (and (vectorp value) (= (length value) length)))
177+
(dotimes (k length)
178+
(should (stringp (aref value k))))))))))
179+
180+
131181
(provide 'test/base)

‎test/format.el

+6
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,10 @@
165165
(datetime--test-formatter times)))))
166166

167167

168+
;; A real bug fixed in 0.9.1. A more thorough test for it is `datetime-locale-database-sanity'.
169+
(ert-deftest datetime-formatting-hebrew-1 ()
170+
(datetime--test-set-up-formatter 'UTC 'he "yyyy G"
171+
(datetime--test-formatter 0)))
172+
173+
168174
(provide 'test/format)

‎timezone-name-data.extmap

-14 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.