File tree Expand file tree Collapse file tree 2 files changed +42
-4
lines changed Expand file tree Collapse file tree 2 files changed +42
-4
lines changed Original file line number Diff line number Diff line change @@ -125,17 +125,17 @@ feature -- Decoder
125125 byte_count := 0
126126
127127 pos := next_encoded_character_position (v , pos )
128- if pos <= n then
128+ if pos < n then
129129 byte 1 := base 64 chars .index_of (v [pos ], 1 ) - 1
130130 byte_count := byte_count + 1
131131
132132 pos := next_encoded_character_position (v , pos )
133- if pos <= n then
133+ if pos < n then
134134 byte 2 := base 64 chars .index_of (v [pos ], 1 ) - 1
135135 byte_count := byte_count + 1
136136
137137 pos := next_encoded_character_position (v , pos )
138- if pos <= n then
138+ if pos < n then
139139 c := v [pos ]
140140 if c /= '=' then
141141 byte 3 := base 64 chars .index_of (c , 1 ) - 1
@@ -150,8 +150,14 @@ feature -- Decoder
150150 byte_count := byte_count + 1
151151 end
152152 end
153+ else
154+ has_error := True
153155 end
156+ else
157+ has_error := True
154158 end
159+ else
160+ has_error := True
155161 end
156162-- pos := pos + byte_count
157163
@@ -293,7 +299,7 @@ feature {NONE} -- Constants
293299 character_map : STRING = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
294300
295301note
296- copyright : " Copyright (c) 1984- 2011, Eiffel Software and others"
302+ copyright : " Copyright (c) 2011-2014 , Eiffel Software and others"
297303 license : " Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
298304 source : " [
299305 Eiffel Software
Original file line number Diff line number Diff line change @@ -34,6 +34,38 @@ feature -- Test routines
3434 assert (" decoded encoded string is same" , u ~ s )
3535 end
3636
37+ feature -- Tests
38+
39+ test_valid_ 64 _encoding
40+ do
41+ assert (" Expected encoded True:" , is_valid_base 64 _encoding ((create {BASE 64 }).encoded_string (" content" )))
42+ end
43+
44+ test_not_valid 64 _encoding
45+ do
46+ assert (" Expected encoded False:" , not is_valid_base 64 _encoding (" content" ))
47+ assert (" Expected encoded False:" , not is_valid_base 64 _encoding (" !@#$%%^" ))
48+ end
49+
50+ feature {NONE } -- Implementation
51+
52+ is_valid_base 64 _encoding (a_string : STRING ): BOOLEAN
53+ -- is `a_string' base64 encoded?
54+ local
55+ l_encoder : BASE 64
56+ l_string : STRING
57+ l_retry : BOOLEAN
58+ do
59+ if not l_retry then
60+ create l_encoder
61+ l_string := l_encoder .decoded_string (a_string )
62+ Result := not l_encoder .has_error
63+ end
64+ rescue
65+ l_retry := True
66+ retry
67+ end
68+
3769note
3870 copyright : " Copyright (c) 1984-2011, Eiffel Software and others"
3971 license : " Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
You can’t perform that action at this time.
0 commit comments