Skip to content

Commit

Permalink
Fixed various issue with parsing string (such as \t and related),
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jocelyn committed Sep 24, 2014
1 parent de28294 commit 19dbbf8
Show file tree
Hide file tree
Showing 40 changed files with 1,115 additions and 782 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Expand Up @@ -7,3 +7,4 @@
*.ecf text
*.bat text
*.json text
*.txt text
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,2 +1,2 @@
*.swp
EIFGENs
EIFGENs/
4 changes: 2 additions & 2 deletions History.txt
@@ -1,4 +1,4 @@
History file for EJSON
History file for EJSON
======================

team: ""
Expand All @@ -23,4 +23,4 @@ implementation.

*Added converters and factory classes

*Added new top level directories; library, test, build and example
*Added new top level directories; library, test, build and example
8 changes: 4 additions & 4 deletions License.txt
@@ -1,20 +1,20 @@
Copyright (c) 2010 Javier Velilla and others, http://ejson.origo.ethz.ch
Copyright (c) 2010 Javier Velilla and others, http://ejson.origo.ethz.ch


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

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

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

to_json (o: like object): detachable JSON_OBJECT
local
c: HASH_TABLE_ITERATION_CURSOR [ANY, HASHABLE]
js: JSON_STRING
failed: BOOLEAN
do
create Result.make
from
c := o.new_cursor
until
c.after
across
o as c
loop
if attached {JSON_STRING} json.value (c.key) as l_key then
js := l_key
else
create js.make_json (c.key.out)
if attached {READABLE_STRING_GENERAL} c.key as s_key then
create js.make_from_string_general (s_key)
else
create js.make_from_string (c.key.out)
end
end
if attached json.value (c.item) as jv then
Result.put (jv, js)
else
failed := True
end
c.forth
end
if failed then
Result := Void
Expand Down
Expand Up @@ -51,17 +51,15 @@ feature -- Conversion
to_json (o: like object): detachable JSON_ARRAY
local
c: ITERATION_CURSOR [detachable ANY]
jv: detachable JSON_VALUE
failed: BOOLEAN
do
create Result.make_array
create Result.make (o.count)
from
c := o.new_cursor
until
c.after
loop
jv := json.value (c.item)
if jv /= Void then
if attached json.value (c.item) as jv then
Result.add (jv)
else
failed := True
Expand Down
26 changes: 12 additions & 14 deletions library/kernel/ejson.e → library/converter/support/ejson.e
Expand Up @@ -27,7 +27,7 @@ feature -- Access
if an_object = Void then
create {JSON_NULL} Result
elseif attached {BOOLEAN} an_object as b then
create {JSON_BOOLEAN} Result.make_boolean (b)
create {JSON_BOOLEAN} Result.make (b)
elseif attached {INTEGER_8} an_object as i8 then
create {JSON_NUMBER} Result.make_integer (i8)
elseif attached {INTEGER_16} an_object as i16 then
Expand All @@ -49,7 +49,7 @@ feature -- Access
elseif attached {REAL_64} an_object as r64 then
create {JSON_NUMBER} Result.make_real (r64)
elseif attached {ARRAY [detachable ANY]} an_object as a then
create ja.make_array
create ja.make (a.count)
from
i := a.lower
until
Expand All @@ -66,13 +66,13 @@ feature -- Access
end
Result := ja
elseif attached {CHARACTER_8} an_object as c8 then
create {JSON_STRING} Result.make_json (c8.out)
create {JSON_STRING} Result.make_from_string (c8.out)
elseif attached {CHARACTER_32} an_object as c32 then
create {JSON_STRING} Result.make_json (c32.out)
create {JSON_STRING} Result.make_from_string_32 (create {STRING_32}.make_filled (c32, 1))
elseif attached {STRING_8} an_object as s8 then
create {JSON_STRING} Result.make_json (s8)
create {JSON_STRING} Result.make_from_string (s8)
elseif attached {STRING_32} an_object as s32 then
create {JSON_STRING} Result.make_json_from_string_32 (s32)
create {JSON_STRING} Result.make_from_string_32 (s32)
end
if Result = Void then
-- Now check the converters
Expand Down Expand Up @@ -162,12 +162,10 @@ feature -- Access
-- "eJSON exception" if unable to convert value.
require
json_not_void: json /= Void
local
jv: detachable JSON_VALUE
do
json_parser.set_representation (json)
jv := json_parser.parse
if jv /= Void then
json_parser.parse_content
if json_parser.is_valid and then attached json_parser.parsed_json_value as jv then
Result := object (jv, base_class)
end
end
Expand All @@ -192,8 +190,8 @@ feature -- Access
js_key, js_value: JSON_STRING
do
create Result.make
create js_key.make_json ("$ref")
create js_value.make_json (s)
create js_key.make_from_string ("$ref")
create js_value.make_from_string (s)
Result.put (js_value, js_key)
end

Expand All @@ -207,7 +205,7 @@ feature -- Access
local
c: ITERATION_CURSOR [STRING]
do
create Result.make_array
create Result.make (l.count)
from
c := l.new_cursor
until
Expand Down Expand Up @@ -264,7 +262,7 @@ feature {NONE} -- Implementation (JSON parser)

json_parser: JSON_PARSER
once
create Result.make_parser ("")
create Result.make_with_string ("{}")
end

end -- class EJSON
Expand Up @@ -14,7 +14,7 @@ note
class
SHARED_EJSON

feature
feature -- Access

json: EJSON
-- A shared EJSON instance with default converters for
Expand Down
39 changes: 0 additions & 39 deletions library/extras/file/json_file_reader.e

This file was deleted.

File renamed without changes.
19 changes: 6 additions & 13 deletions library/json-safe.ecf
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="json" uuid="4E21C3BD-7951-4C6E-A673-431E762D7414" library_target="json">
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="json" uuid="4E21C3BD-7951-4C6E-A673-431E762D7414" library_target="json">
<target name="json">
<root all_classes="true"/>
<file_rule>
Expand All @@ -9,20 +9,13 @@
</file_rule>
<option trace="false" profile="false" debug="false" warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="standard" namespace="EJSON.Library">
<assertions/>
<warning name="export_class_missing" enabled="false"/>
<warning name="old_verbatim_strings" enabled="false"/>
<warning name="syntax" enabled="false"/>
<warning name="vjrv" enabled="false"/>
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf" readonly="true"/>
<cluster name="json" location=".\" recursive="true">
<file_rule>
<exclude>^/gobo$</exclude>
<exclude>^/kernel$</exclude>
<exclude>^/extras$</exclude>
</file_rule>
<cluster name="kernel" location=".\kernel\" recursive="true"/>
<cluster name="extras" location=".\extras\" recursive="true"/>
<cluster name="json" location=".\" >
<cluster name="json_kernel" location=".\kernel" recursive="true"/>
<cluster name="json_parser" location=".\parser" recursive="true"/>
<cluster name="json_utility" location=".\utility" recursive="true"/>
</cluster>
<cluster name="json_converter" location=".\converter" recursive="true"/>
</target>
</system>
17 changes: 5 additions & 12 deletions library/json.ecf
Expand Up @@ -9,20 +9,13 @@
</file_rule>
<option trace="false" profile="false" debug="false" warning="true" full_class_checking="true" void_safety="none" syntax="standard" namespace="EJSON.Library">
<assertions/>
<warning name="export_class_missing" enabled="false"/>
<warning name="old_verbatim_strings" enabled="false"/>
<warning name="syntax" enabled="false"/>
<warning name="vjrv" enabled="false"/>
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf" readonly="true"/>
<cluster name="json" location=".\" recursive="true">
<file_rule>
<exclude>^/gobo$</exclude>
<exclude>^/kernel$</exclude>
<exclude>^/extras$</exclude>
</file_rule>
<cluster name="kernel" location=".\kernel\" recursive="true"/>
<cluster name="extras" location=".\extras\" recursive="true"/>
<cluster name="json" location=".\" >
<cluster name="json_kernel" location=".\kernel" recursive="true"/>
<cluster name="json_parser" location=".\parser" recursive="true"/>
<cluster name="json_utility" location=".\utility" recursive="true"/>
</cluster>
<cluster name="json_converter" location=".\converter" recursive="true"/>
</target>
</system>
2 changes: 1 addition & 1 deletion library/json_gobo_extension.ecf
Expand Up @@ -12,6 +12,6 @@
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf" readonly="true"/>
<library name="json" location="json.ecf" readonly="true"/>
<library name="gobo_structure" location="$ISE_LIBRARY\library\gobo\gobo_structure.ecf"/>
<cluster name="json_gobo" location=".\gobo" recursive="true" />
<cluster name="json_gobo_converter" location=".\gobo_converter" recursive="true" />
</target>
</system>

0 comments on commit 19dbbf8

Please sign in to comment.