crack 0.4.0 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e6d7eabbf55c05bb0d5ad82fa7ba5bda9ffd9d59afa880eb113c17c3045aaa4f
4
+ data.tar.gz: af13a8caa99d12d057f7ec55c1f9142f0bae6f3ec7ad59c06fbd8cf2be259ef8
5
+ SHA512:
6
+ metadata.gz: 936f41453b1fe901f44315a4634f489ef57c567287cd88a90534e0afd53bac92ade2376d52558405777c8b8e40beba9b3562c2ab2d887f515bc84d268b268cd2
7
+ data.tar.gz: c1993458cf230034223899dd739ea6611cc1eb962f1785421ab6fd43d390828288cc6ba1604f9477a5c41e1db915542455bb35dd12d2503a78c571090cbf9501
@@ -3,29 +3,21 @@
3
3
  # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
4
4
  # 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.
5
5
 
6
- require 'yaml'
7
6
  require 'strscan'
8
7
 
9
8
  module Crack
10
9
  class JSON
11
10
  def self.parser_exceptions
12
- @parser_exceptions ||= begin
13
- exceptions = [ArgumentError]
14
-
15
- if const_defined?(:Psych)
16
- if Psych.const_defined?(:SyntaxError)
17
- exceptions << Psych::SyntaxError
18
- end
19
- end
20
-
21
- exceptions
22
- end
11
+ @parser_exceptions ||= [ArgumentError, Psych::SyntaxError]
23
12
  end
24
13
 
25
14
  def self.parse(json)
26
- YAML.load(unescape(convert_json_to_yaml(json)))
15
+ yaml = unescape(convert_json_to_yaml(json))
16
+ YAML.safe_load(yaml, [Regexp, Date, Time])
27
17
  rescue *parser_exceptions
28
18
  raise ParseError, "Invalid JSON string"
19
+ rescue Psych::DisallowedClass
20
+ yaml
29
21
  end
30
22
 
31
23
  protected
@@ -38,12 +30,12 @@ module Crack
38
30
  end
39
31
 
40
32
  # matches YAML-formatted dates
41
- DATE_REGEX = /^\d{4}-\d{2}-\d{2}$|^\d{4}-\d{1,2}-\d{1,2}[T \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?)?$/
33
+ DATE_REGEX = /^\d{4}-\d{2}-\d{2}$|^\d{4}-\d{1,2}-\d{1,2}[T \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?)$/
42
34
 
43
35
  # Ensure that ":" and "," are always followed by a space
44
36
  def self.convert_json_to_yaml(json) #:nodoc:
45
37
  json = String.new(json) #can't modify a frozen string
46
- scanner, quoting, marks, pos, times = StringScanner.new(json), false, [], nil, []
38
+ scanner, quoting, marks, pos, date_starts, date_ends = StringScanner.new(json), false, [], nil, [], []
47
39
  while scanner.scan_until(/(\\['"]|['":,\/\\]|\\.)/)
48
40
  case char = scanner[1]
49
41
  when '"', "'"
@@ -56,7 +48,8 @@ module Crack
56
48
  # oh, and increment them for each current mark, each one is an extra padded space that bumps
57
49
  # the position in the final YAML output
58
50
  total_marks = marks.size
59
- times << pos+total_marks << scanner.pos+total_marks
51
+ date_starts << pos+total_marks
52
+ date_ends << scanner.pos+total_marks
60
53
  end
61
54
  quoting = false
62
55
  end
@@ -76,7 +69,7 @@ module Crack
76
69
  if marks.empty?
77
70
  json.gsub(/\\\//, '/')
78
71
  else
79
- left_pos = [-1].push(*marks)
72
+ left_pos = marks.clone.unshift(-1)
80
73
  right_pos = marks << json.length
81
74
  output = []
82
75
  left_pos.each_with_index do |left, i|
@@ -84,10 +77,22 @@ module Crack
84
77
  end
85
78
  output = output * " "
86
79
 
87
- times.each { |i| output[i-1] = ' ' }
80
+ format_dates(output, date_starts, date_ends)
88
81
  output.gsub!(/\\\//, '/')
89
82
  output
90
83
  end
91
84
  end
85
+
86
+ def self.format_dates(output, date_starts, date_ends)
87
+ if YAML.constants.include?('Syck')
88
+ (date_starts + date_ends).each { |i| output[i-1] = ' ' }
89
+ else
90
+ extra_chars_to_be_added = 0
91
+ date_starts.each do |i|
92
+ output[i-2+extra_chars_to_be_added] = '!!timestamp '
93
+ extra_chars_to_be_added += 10
94
+ end
95
+ end
96
+ end
92
97
  end
93
98
  end
@@ -1,3 +1,3 @@
1
1
  module Crack
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.5"
3
3
  end
metadata CHANGED
@@ -1,32 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
5
- prerelease:
4
+ version: 0.4.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - John Nunemaker
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-05 00:00:00.000000000 Z
11
+ date: 2020-12-27 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: safe_yaml
14
+ name: rexml
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
- version: 0.9.0
19
+ version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: 0.9.0
26
+ version: '0'
30
27
  description: Really simple JSON and XML parsing, ripped from Merb and Rails.
31
28
  email:
32
29
  - nunemaker@gmail.com
@@ -34,60 +31,32 @@ executables: []
34
31
  extensions: []
35
32
  extra_rdoc_files: []
36
33
  files:
37
- - .gitignore
38
- - Gemfile
39
- - Gemfile.lock
40
- - History
41
- - LICENSE
42
- - README.md
43
- - crack.gemspec
44
34
  - lib/crack.rb
45
35
  - lib/crack/json.rb
46
36
  - lib/crack/util.rb
47
37
  - lib/crack/version.rb
48
38
  - lib/crack/xml.rb
49
- - script/bootstrap
50
- - script/release
51
- - script/test
52
- - test/data/twittersearch-firefox.json
53
- - test/data/twittersearch-ie.json
54
- - test/hash_test.rb
55
- - test/json_test.rb
56
- - test/parser_test.rb
57
- - test/string_test.rb
58
- - test/test_helper.rb
59
- - test/xml_test.rb
60
- homepage: http://github.com/jnunemaker/crack
39
+ homepage: https://github.com/jnunemaker/crack
61
40
  licenses:
62
41
  - MIT
63
- post_install_message:
42
+ metadata: {}
43
+ post_install_message:
64
44
  rdoc_options: []
65
45
  require_paths:
66
46
  - lib
67
47
  required_ruby_version: !ruby/object:Gem::Requirement
68
- none: false
69
48
  requirements:
70
- - - ! '>='
49
+ - - ">="
71
50
  - !ruby/object:Gem::Version
72
51
  version: '0'
73
52
  required_rubygems_version: !ruby/object:Gem::Requirement
74
- none: false
75
53
  requirements:
76
- - - ! '>='
54
+ - - ">="
77
55
  - !ruby/object:Gem::Version
78
56
  version: '0'
79
57
  requirements: []
80
- rubyforge_project:
81
- rubygems_version: 1.8.23
82
- signing_key:
83
- specification_version: 3
58
+ rubygems_version: 3.1.4
59
+ signing_key:
60
+ specification_version: 4
84
61
  summary: Really simple JSON and XML parsing, ripped from Merb and Rails.
85
- test_files:
86
- - test/data/twittersearch-firefox.json
87
- - test/data/twittersearch-ie.json
88
- - test/hash_test.rb
89
- - test/json_test.rb
90
- - test/parser_test.rb
91
- - test/string_test.rb
92
- - test/test_helper.rb
93
- - test/xml_test.rb
62
+ test_files: []
data/.gitignore DELETED
@@ -1,7 +0,0 @@
1
- *.sw?
2
- .DS_Store
3
- coverage
4
- rdoc
5
- pkg
6
- *.gem
7
- /.bundle
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
3
-
4
- gem "rake"
5
- gem "jnunemaker-matchy"
6
- gem "minitest"
@@ -1,22 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- crack (0.3.2)
5
- safe_yaml (~> 0.9.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- jnunemaker-matchy (0.4.0)
11
- minitest (5.0.3)
12
- rake (10.0.3)
13
- safe_yaml (0.9.2)
14
-
15
- PLATFORMS
16
- ruby
17
-
18
- DEPENDENCIES
19
- crack!
20
- jnunemaker-matchy
21
- minitest
22
- rake
data/History DELETED
@@ -1,25 +0,0 @@
1
- == 0.1.7 2010-02-19
2
- * 1 minor patch
3
- * Added patch from @purp for ISO 8601 date/time format
4
- == 0.1.6 2010-01-31
5
- * 1 minor patch
6
- * Added Crack::VERSION constant - http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices
7
- == 0.1.5 2010-01-27
8
- * 1 minor patch
9
- * Strings that begin with dates shouldn't be parsed as such (sandro)
10
-
11
- == 0.1.3 2009-06-22
12
- * 1 minor patch
13
- * Parsing a text node with attributes stores them in the attributes method (tamalw)
14
-
15
- == 0.1.2 2009-04-21
16
- * 2 minor patches
17
- * Correct unnormalization of attribute values (der-flo)
18
- * Fix error in parsing YAML in the case where a hash value ends with backslashes, and there are subsequent values in the hash (deadprogrammer)
19
-
20
- == 0.1.1 2009-03-31
21
- * 1 minor patch
22
- * Parsing empty or blank xml now returns empty hash instead of raising error.
23
-
24
- == 0.1.0 2009-03-28
25
- * Initial release.
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009 John Nunemaker
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,44 +0,0 @@
1
- # crack
2
-
3
- Really simple JSON and XML parsing, ripped from Merb and Rails. The XML parser is ripped from Merb and the JSON parser is ripped from Rails. I take no credit, just packaged them for all to enjoy and easily use.
4
-
5
- ## compatibility
6
-
7
- * ruby 1.8.7
8
- * ruby 1.9+ (3 failures related to time parsing, would love it if someone could figure them out)
9
-
10
- ## note on patches/pull requests
11
-
12
- * Fork the project.
13
- * Make your feature addition or bug fix.
14
- * Add tests for it. This is important so I don't break it in a future version unintentionally.
15
- * `script/test` - this will bootstrap and run the tests
16
- * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself in another branch so I can ignore when I pull)
17
- * Send me a pull request. Bonus points for topic branches.
18
-
19
- ## usage
20
-
21
- ```ruby
22
- gem 'crack' # in Gemfile
23
- require 'crack' # for xml and json
24
- require 'crack/json' # for just json
25
- require 'crack/xml' # for just xml
26
- ```
27
-
28
- ## examples
29
-
30
- ```ruby
31
- Crack::XML.parse("<tag>This is the contents</tag>")
32
- # => {'tag' => 'This is the contents'}
33
-
34
- Crack::JSON.parse('{"tag":"This is the contents"}')
35
- # => {'tag' => 'This is the contents'}
36
- ```
37
-
38
- ## Copyright
39
-
40
- Copyright (c) 2009 John Nunemaker. See LICENSE for details.
41
-
42
- ## Docs
43
-
44
- http://rdoc.info/projects/jnunemaker/crack
@@ -1,20 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/crack/version', __FILE__)
3
-
4
- Gem::Specification.new do |gem|
5
- gem.authors = ["John Nunemaker"]
6
- gem.email = ["nunemaker@gmail.com"]
7
- gem.description = %q{Really simple JSON and XML parsing, ripped from Merb and Rails.}
8
- gem.summary = %q{Really simple JSON and XML parsing, ripped from Merb and Rails.}
9
- gem.homepage = "http://github.com/jnunemaker/crack"
10
-
11
- gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
- gem.files = `git ls-files`.split("\n")
13
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
- gem.name = "crack"
15
- gem.require_paths = ["lib"]
16
- gem.version = Crack::VERSION
17
- gem.license = "MIT"
18
-
19
- gem.add_dependency "safe_yaml", "~> 0.9.0"
20
- end
@@ -1,21 +0,0 @@
1
- #!/bin/sh
2
- #/ Usage: bootstrap [bundle options]
3
- #/
4
- #/ Bundle install the dependencies.
5
- #/
6
- #/ Examples:
7
- #/
8
- #/ bootstrap
9
- #/ bootstrap --local
10
- #/
11
-
12
- set -e
13
- cd $(dirname "$0")/..
14
-
15
- [ "$1" = "--help" -o "$1" = "-h" -o "$1" = "help" ] && {
16
- grep '^#/' <"$0"| cut -c4-
17
- exit 0
18
- }
19
-
20
- rm -rf .bundle/{binstubs,config}
21
- bundle install --binstubs .bundle/binstubs --path .bundle --quiet "$@"
@@ -1,42 +0,0 @@
1
- #!/bin/sh
2
- #/ Usage: release
3
- #/
4
- #/ Tag the version in the repo and push the gem.
5
- #/
6
-
7
- set -e
8
- cd $(dirname "$0")/..
9
-
10
- [ "$1" = "--help" -o "$1" = "-h" -o "$1" = "help" ] && {
11
- grep '^#/' <"$0"| cut -c4-
12
- exit 0
13
- }
14
-
15
- gem_name=crack
16
-
17
- # Build a new gem archive.
18
- rm -rf $gem_name-*.gem
19
- gem build -q $gem_name.gemspec
20
-
21
- # Make sure we're on the master branch.
22
- (git branch | grep -q '* master') || {
23
- echo "Only release from the master branch."
24
- exit 1
25
- }
26
-
27
- # Figure out what version we're releasing.
28
- tag=v`ls $gem_name-*.gem | sed "s/^$gem_name-\(.*\)\.gem$/\1/"`
29
-
30
- echo "Releasing $tag"
31
-
32
- # Make sure we haven't released this version before.
33
- git fetch -t origin
34
-
35
- (git tag -l | grep -q "$tag") && {
36
- echo "Whoops, there's already a '${tag}' tag."
37
- exit 1
38
- }
39
-
40
- # Tag it and bag it.
41
- gem push $gem_name-*.gem && git tag "$tag" &&
42
- git push origin master && git push origin "$tag"
@@ -1,25 +0,0 @@
1
- #!/bin/sh
2
- #/ Usage: test [individual test file]
3
- #/
4
- #/ Bootstrap and run all tests or an individual test.
5
- #/
6
- #/ Examples:
7
- #/
8
- #/ # run all tests
9
- #/ test
10
- #/
11
- #/ # run individual test
12
- #/ test test/controller_instrumentation_test.rb
13
- #/
14
-
15
- set -e
16
- cd $(dirname "$0")/..
17
-
18
- [ "$1" = "--help" -o "$1" = "-h" -o "$1" = "help" ] && {
19
- grep '^#/' <"$0"| cut -c4-
20
- exit 0
21
- }
22
-
23
- script/bootstrap && ruby -I lib -I test -r rubygems \
24
- -e 'require "bundler/setup"' \
25
- -e '(ARGV.empty? ? Dir["test/**/*_test.rb"] : ARGV).each { |f| load f }' -- "$@"