Skip to content

Commit dcf38a4

Browse files
authored
Ensure to not parse “exotic” (non-Arabic) digits
This PR adds a few tests to make sure that we don’t accidentally accept any kinds of digits that aren’t Arabic numerals.
1 parent 6f2c7a1 commit dcf38a4

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

klog/date_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ func TestParseDateFailsIfMalformed(t *testing.T) {
114114
"20-12-12",
115115
"asdf",
116116
"01.01.2000",
117+
"⠃⠚⠚⠚-⠁⠃-⠚⠛", // Braille digits
118+
"二〇〇〇-一二-〇四", // Japanese digits
119+
"᠒᠐᠐᠐-᠑᠒-᠐᠗", // Mongolean digits
117120
} {
118121
d, err := NewDateFromString(s)
119122
assert.Nil(t, d)

klog/duration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (d duration) ToStringWithSign() string {
111111
return s
112112
}
113113

114-
var durationPattern = regexp.MustCompile(`^(-|\+)?((\d+)h)?((\d+)m)?$`)
114+
var durationPattern = regexp.MustCompile(`^([-+])?((\d+)h)?((\d+)m)?$`)
115115

116116
func NewDurationFromString(hhmm string) (Duration, error) {
117117
match := durationPattern.FindStringSubmatch(hhmm)

klog/duration_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ func TestParsingFailsWithInvalidValue(t *testing.T) {
130130
"asdf",
131131
"6h asdf",
132132
"qwer 30m",
133+
"⠙⠛m", // Braille digits
134+
"四二h", // Japanese digits
135+
"᠒h᠐᠒m", // Mongolean digits
133136
} {
134137
duration, err := NewDurationFromString(d)
135138
assert.EqualError(t, err, "MALFORMED_DURATION")

klog/time_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ func TestParseMalformedTimesFail(t *testing.T) {
207207
"13:3", // Minutes must have 2 digits
208208
"-14:12", // Hours cannot be negative
209209
"14:-12", // Minutes cannot be negative
210+
"⠃⠚:⠙⠛", // Braille digits
211+
"四:二八", // Japanese digits
212+
"᠒᠐:᠑᠒", // Mongolean digits
210213
} {
211214
tm, err := NewTimeFromString(s)
212215
require.Nil(t, tm, s)

0 commit comments

Comments
 (0)