Skip to content

Commit 19dbbf8

Browse files
committed
Fixed various issue with parsing string (such as \t and related),
Implemented escaping of slash '/' only in case of '</' to avoid potential issue with javascript and </script> Many feature renaming to match Eiffel style and naming convention, kept previous feature as obsolete. Restructured the library to make easy extraction of "converter" classes if needed in the future. Updated part of the code to use new feature names.
1 parent de28294 commit 19dbbf8

40 files changed

+1115
-782
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
*.ecf text
88
*.bat text
99
*.json text
10+
*.txt text

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
*.swp
2-
EIFGENs
2+
EIFGENs/

History.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
History file for EJSON
1+
History file for EJSON
22
======================
33

44
team: ""
@@ -23,4 +23,4 @@ implementation.
2323

2424
*Added converters and factory classes
2525

26-
*Added new top level directories; library, test, build and example
26+
*Added new top level directories; library, test, build and example

License.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
Copyright (c) 2010 Javier Velilla and others, http://ejson.origo.ethz.ch
1+
Copyright (c) 2010 Javier Velilla and others, http://ejson.origo.ethz.ch
22

33

44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal
66
in the Software without restriction, including without limitation the rights
77
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
88
copies of the Software, and to permit persons to whom the Software is
9-
furnished to do so, subject to the following conditions:
9+
furnished to do so, subject to the following conditions:
1010

1111
The above copyright notice and this permission notice shall be included in
12-
all copies or substantial portions of the Software.
12+
all copies or substantial portions of the Software.
1313

1414
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1515
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1616
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1717
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1818
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1919
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20-
THE SOFTWARE.
20+
THE SOFTWARE.
File renamed without changes.

library/kernel/converters/json_hash_table_converter.e renamed to library/converter/json_hash_table_converter.e

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,27 @@ feature -- Conversion
5252

5353
to_json (o: like object): detachable JSON_OBJECT
5454
local
55-
c: HASH_TABLE_ITERATION_CURSOR [ANY, HASHABLE]
5655
js: JSON_STRING
5756
failed: BOOLEAN
5857
do
5958
create Result.make
60-
from
61-
c := o.new_cursor
62-
until
63-
c.after
59+
across
60+
o as c
6461
loop
6562
if attached {JSON_STRING} json.value (c.key) as l_key then
6663
js := l_key
6764
else
68-
create js.make_json (c.key.out)
65+
if attached {READABLE_STRING_GENERAL} c.key as s_key then
66+
create js.make_from_string_general (s_key)
67+
else
68+
create js.make_from_string (c.key.out)
69+
end
6970
end
7071
if attached json.value (c.item) as jv then
7172
Result.put (jv, js)
7273
else
7374
failed := True
7475
end
75-
c.forth
7676
end
7777
if failed then
7878
Result := Void

library/kernel/converters/json_list_converter.e renamed to library/converter/json_list_converter.e

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,15 @@ feature -- Conversion
5151
to_json (o: like object): detachable JSON_ARRAY
5252
local
5353
c: ITERATION_CURSOR [detachable ANY]
54-
jv: detachable JSON_VALUE
5554
failed: BOOLEAN
5655
do
57-
create Result.make_array
56+
create Result.make (o.count)
5857
from
5958
c := o.new_cursor
6059
until
6160
c.after
6261
loop
63-
jv := json.value (c.item)
64-
if jv /= Void then
62+
if attached json.value (c.item) as jv then
6563
Result.add (jv)
6664
else
6765
failed := True

library/kernel/ejson.e renamed to library/converter/support/ejson.e

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ feature -- Access
2727
if an_object = Void then
2828
create {JSON_NULL} Result
2929
elseif attached {BOOLEAN} an_object as b then
30-
create {JSON_BOOLEAN} Result.make_boolean (b)
30+
create {JSON_BOOLEAN} Result.make (b)
3131
elseif attached {INTEGER_8} an_object as i8 then
3232
create {JSON_NUMBER} Result.make_integer (i8)
3333
elseif attached {INTEGER_16} an_object as i16 then
@@ -49,7 +49,7 @@ feature -- Access
4949
elseif attached {REAL_64} an_object as r64 then
5050
create {JSON_NUMBER} Result.make_real (r64)
5151
elseif attached {ARRAY [detachable ANY]} an_object as a then
52-
create ja.make_array
52+
create ja.make (a.count)
5353
from
5454
i := a.lower
5555
until
@@ -66,13 +66,13 @@ feature -- Access
6666
end
6767
Result := ja
6868
elseif attached {CHARACTER_8} an_object as c8 then
69-
create {JSON_STRING} Result.make_json (c8.out)
69+
create {JSON_STRING} Result.make_from_string (c8.out)
7070
elseif attached {CHARACTER_32} an_object as c32 then
71-
create {JSON_STRING} Result.make_json (c32.out)
71+
create {JSON_STRING} Result.make_from_string_32 (create {STRING_32}.make_filled (c32, 1))
7272
elseif attached {STRING_8} an_object as s8 then
73-
create {JSON_STRING} Result.make_json (s8)
73+
create {JSON_STRING} Result.make_from_string (s8)
7474
elseif attached {STRING_32} an_object as s32 then
75-
create {JSON_STRING} Result.make_json_from_string_32 (s32)
75+
create {JSON_STRING} Result.make_from_string_32 (s32)
7676
end
7777
if Result = Void then
7878
-- Now check the converters
@@ -162,12 +162,10 @@ feature -- Access
162162
-- "eJSON exception" if unable to convert value.
163163
require
164164
json_not_void: json /= Void
165-
local
166-
jv: detachable JSON_VALUE
167165
do
168166
json_parser.set_representation (json)
169-
jv := json_parser.parse
170-
if jv /= Void then
167+
json_parser.parse_content
168+
if json_parser.is_valid and then attached json_parser.parsed_json_value as jv then
171169
Result := object (jv, base_class)
172170
end
173171
end
@@ -192,8 +190,8 @@ feature -- Access
192190
js_key, js_value: JSON_STRING
193191
do
194192
create Result.make
195-
create js_key.make_json ("$ref")
196-
create js_value.make_json (s)
193+
create js_key.make_from_string ("$ref")
194+
create js_value.make_from_string (s)
197195
Result.put (js_value, js_key)
198196
end
199197

@@ -207,7 +205,7 @@ feature -- Access
207205
local
208206
c: ITERATION_CURSOR [STRING]
209207
do
210-
create Result.make_array
208+
create Result.make (l.count)
211209
from
212210
c := l.new_cursor
213211
until
@@ -264,7 +262,7 @@ feature {NONE} -- Implementation (JSON parser)
264262

265263
json_parser: JSON_PARSER
266264
once
267-
create Result.make_parser ("")
265+
create Result.make_with_string ("{}")
268266
end
269267

270268
end -- class EJSON

0 commit comments

Comments
 (0)