embulk-parser-query_string 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a2f6dd8e7b04e7bcb973b5b8ef66d475a2301e5
4
- data.tar.gz: 7177bc35ee74ee4e4753f835b115d9fefc464ee5
3
+ metadata.gz: 7bf28a70ddd9f3ec7210201a7f027c05fe675ef7
4
+ data.tar.gz: 2d4fe6c85982222f3fb9eef01cc99efda5f0bba4
5
5
  SHA512:
6
- metadata.gz: 7939b0f651563a556eb28c086298c02edaeab5db3642156e360bc350b4bfbc2403683de9ab5d01ad9fae4255b08377da5697b55d04707fcdfaa0ef84f6baa193
7
- data.tar.gz: 03607bea2d57d0480070877bc0e7cb2b54c2ebc2b2878d56d6ff324903940d31b3372e9ce76070640126ceb8bcfc9b4d0238aab761dfb07b1d7d61a84173f629
6
+ metadata.gz: 8aee02b66458e5ff1eb71de855030a0e56162cb1c1ed1ad0953498ce27c4782d9c3297bacf513fbb7f704447778453bde3e767fb9dc537a3a8ec1d31c0c60f2f
7
+ data.tar.gz: 83cabae95cba6fa468c7e8fcd97ce1bcdb831d7859b66161c7c6d8379b2bfdc61e178eaa7d0a84337409a87f436bce31f3ff5f9e6f9a83bc15e991876350c800
@@ -1,10 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - jruby-9000
4
-
5
- before_install:
6
- - rvm get head
7
- - rvm use jruby-9.0.1.0 --install
3
+ - jruby-9.0.1.0
4
+ jdk:
5
+ - oraclejdk8
6
+ env:
7
+ global:
8
+ - JRUBY_OPTS="-Xcli.debug=true --debug"
8
9
 
9
10
  addons:
10
11
  code_climate:
@@ -13,8 +14,6 @@ addons:
13
14
  notifications:
14
15
  slack:
15
16
  secure: "QRZ6zQxcRdN2XylIz+b46TbYIv7x5Ko7Y0Mi0aGbf7Wg1xfnS4X2FZKp8gF+RH1qjT6CYsQFUpPBhPVCMx0fP0ik5/gBrdngrj0htludvQ5CTK2oVegM1VC5NSn+gi8bt2F20Ode9fxU5OS1HDzNR9sjPz3W7miMUNDZoYPy77Om/CvmVkBbGyMkWnfwhEvwnL8JpBNpklDvrUUKznNsAcSbKQBMBAglFMds/OaHXCkK142zMbSlHMctch1VDAKhX9/6M3v8v6ZRheX68+VVCz3nTrTF0/lnYh3ig9ey3DNlgkZUqK2gmypnhTE6tpeibHdyVa8qOMNzyAgltu1qIhFHN390WMk9gZXEcvWG3m++PMAIKKtd4varbH1vdCeHOGUV7GRgarcfSMvJ54I9xc5GkUnAhjRKj8xDzYzhkXwApD8eqWb2RgGXUm6G4cKj0MeQ4WBqHr9FOW/4EJcZoztFi0YlP7KE+6xptBJU479KSsv31BwHrMfblObOOj58C7gUfdbTCByxng0u1axxvixL8zJwgHvFND3/4yoXoCCgm0DXBPbi6B5xpt8QmN6K4E5sMGrppTI7VwJqkcwkVD0EEeCedRNiWLTaxlKpLYxYnoXwEnpm9o2WXWa+PjkWeawsnJvV5IAt6oJhaK22VqJN86Macuu+nCdeF1/0TZU="
16
- jdk:
17
- - oraclejdk8
18
17
 
19
18
  gemfile:
20
19
  - gemfiles/embulk-0.7-latest
@@ -23,6 +22,3 @@ gemfile:
23
22
  - gemfiles/embulk-0.7.4
24
23
  - gemfiles/embulk-latest
25
24
 
26
- matrix:
27
- allow_failures:
28
- - gemfile: gemfiles/embulk-0.6.22
@@ -1,6 +1,12 @@
1
1
  language: ruby
2
2
  rvm:
3
- - jruby-19mode
3
+ - jruby-9.0.1.0
4
+ jdk:
5
+ - oraclejdk8
6
+ env:
7
+ global:
8
+ - JRUBY_OPTS="-Xcli.debug=true --debug"
9
+
4
10
  addons:
5
11
  code_climate:
6
12
  repo_token:
@@ -8,14 +14,9 @@ addons:
8
14
  notifications:
9
15
  slack:
10
16
  secure: "QRZ6zQxcRdN2XylIz+b46TbYIv7x5Ko7Y0Mi0aGbf7Wg1xfnS4X2FZKp8gF+RH1qjT6CYsQFUpPBhPVCMx0fP0ik5/gBrdngrj0htludvQ5CTK2oVegM1VC5NSn+gi8bt2F20Ode9fxU5OS1HDzNR9sjPz3W7miMUNDZoYPy77Om/CvmVkBbGyMkWnfwhEvwnL8JpBNpklDvrUUKznNsAcSbKQBMBAglFMds/OaHXCkK142zMbSlHMctch1VDAKhX9/6M3v8v6ZRheX68+VVCz3nTrTF0/lnYh3ig9ey3DNlgkZUqK2gmypnhTE6tpeibHdyVa8qOMNzyAgltu1qIhFHN390WMk9gZXEcvWG3m++PMAIKKtd4varbH1vdCeHOGUV7GRgarcfSMvJ54I9xc5GkUnAhjRKj8xDzYzhkXwApD8eqWb2RgGXUm6G4cKj0MeQ4WBqHr9FOW/4EJcZoztFi0YlP7KE+6xptBJU479KSsv31BwHrMfblObOOj58C7gUfdbTCByxng0u1axxvixL8zJwgHvFND3/4yoXoCCgm0DXBPbi6B5xpt8QmN6K4E5sMGrppTI7VwJqkcwkVD0EEeCedRNiWLTaxlKpLYxYnoXwEnpm9o2WXWa+PjkWeawsnJvV5IAt6oJhaK22VqJN86Macuu+nCdeF1/0TZU="
11
- jdk:
12
- - oraclejdk8
13
17
 
14
18
  gemfile:
15
19
  <% versions.each do |file| -%>
16
20
  - gemfiles/<%= file %>
17
21
  <% end -%>
18
22
 
19
- matrix:
20
- allow_failures:
21
- - gemfile: gemfiles/embulk-0.6.22
@@ -1,3 +1,9 @@
1
+ ## 0.3.1 - 2015-10-20
2
+
3
+ * [enhancement] Raise ConfigError if type cast failed [#34](https://github.com/treasure-data/embulk-parser-query_string/pull/34)
4
+ * [maintenance] Use addressable gem to parse uri [#35](https://github.com/treasure-data/embulk-parser-query_string/pull/35)
5
+ * [maintenance] Fix coverage [#36](https://github.com/treasure-data/embulk-parser-query_string/pull/36)
6
+
1
7
  ## 0.3.0 - 2015-10-06
2
8
 
3
9
  **This version supports Embulk 0.7 or later, and drops Embulk 0.6 or earlier, so if you want to use this plugin with Embulk 0.6 or earlier, please use 0.2.1.**
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "embulk-parser-query_string"
4
- spec.version = "0.3.0"
4
+ spec.version = "0.3.1"
5
5
  spec.authors = ["yoshihara", "uu59"]
6
6
  spec.summary = "Query String parser plugin for Embulk"
7
7
  spec.description = "Parses Query String files read by other file input plugins."
@@ -13,6 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.test_files = spec.files.grep(%r{^(test|spec)/})
14
14
  spec.require_paths = ["lib"]
15
15
 
16
+ spec.add_dependency 'addressable'
16
17
  spec.add_development_dependency 'embulk', [">= 0.7.2", "< 1.0"]
17
18
  spec.add_development_dependency 'bundler', ['~> 1.0']
18
19
  spec.add_development_dependency 'everyleaf-embulk_helper'
@@ -1,4 +1,4 @@
1
- require "uri"
1
+ require "addressable/uri"
2
2
 
3
3
  module Embulk
4
4
  module Parser
@@ -50,6 +50,20 @@ module Embulk
50
50
  page_builder.finish
51
51
  end
52
52
 
53
+ def self.valid_query_string?(qs)
54
+ if qs.match(/[\s]/)
55
+ Embulk.logger.warn "'#{qs}' contains unescaped space"
56
+ return false
57
+ end
58
+
59
+ if qs.match(/[^\x20-\x7e]/)
60
+ Embulk.logger.warn "'#{qs}' contains non-ascii character (maybe unescaped)"
61
+ return false
62
+ end
63
+
64
+ true
65
+ end
66
+
53
67
  def self.parse(line, options = {})
54
68
  if options[:capture]
55
69
  line = line.match(options[:capture]).to_a[1] || ""
@@ -64,7 +78,12 @@ module Embulk
64
78
  end
65
79
 
66
80
  begin
67
- Hash[URI.decode_www_form(line)]
81
+ uri = Addressable::URI.parse("?#{line}")
82
+ if valid_query_string?(uri.query)
83
+ uri.query_values(Hash)
84
+ else
85
+ nil
86
+ end
68
87
  rescue ArgumentError
69
88
  Embulk.logger.warn "Failed parse: #{line}"
70
89
  nil
@@ -95,8 +114,7 @@ module Embulk
95
114
  value.to_s
96
115
  end
97
116
  rescue => e
98
- Embulk.logger.error "Cast failed '#{value}' as '#{column.type}' (key is '#{column.name}')"
99
- raise e
117
+ raise ConfigError.new("Cast failed '#{value}' as '#{column.type}' (key is '#{column.name}')")
100
118
  end
101
119
  end
102
120
 
@@ -30,7 +30,7 @@ module Embulk
30
30
  end
31
31
 
32
32
  def test_warn_invalid_columns
33
- mock(Embulk.logger).warn(/Failed parse/)
33
+ mock(Embulk.logger).warn(anything)
34
34
 
35
35
  QueryString.new.guess_lines(config, self.class.sample_lines_with_invalid)
36
36
  end
@@ -6,6 +6,7 @@ module Embulk
6
6
  module Parser
7
7
  class QueryStringTest < Test::Unit::TestCase
8
8
  class TestParse < self
9
+
9
10
  def test_without_options
10
11
  result = QueryString.parse(line)
11
12
  assert_equal(expected, result)
@@ -32,7 +33,7 @@ module Embulk
32
33
  end
33
34
 
34
35
  def test_with_invalid
35
- mock(Embulk.logger).warn(/#{invalid_line}/) # display whole line if given line is invalid
36
+ mock(Embulk.logger).warn(/'#{invalid_line}'/) # display whole line if given line is invalid
36
37
  result = QueryString.parse(invalid_line)
37
38
  assert_nil(result)
38
39
  end
@@ -94,6 +95,16 @@ module Embulk
94
95
  plugin.send(:process_line, value_nonexist_line)
95
96
  end
96
97
 
98
+ def test_wrong_type_configured
99
+ # NOTE: assert_raise(Embulk::ConfigError) do ... end can't detect correctly
100
+ begin
101
+ plugin.send(:process_line, value_invalid_data_type)
102
+ assert false
103
+ rescue => e
104
+ assert e.is_a?(Embulk::ConfigError)
105
+ end
106
+ end
107
+
97
108
  private
98
109
 
99
110
  def line
@@ -103,6 +114,10 @@ module Embulk
103
114
  def value_nonexist_line
104
115
  "foo=FOO&bar=&baz=2015-07-08T16:25:46"
105
116
  end
117
+
118
+ def value_invalid_data_type
119
+ "foo=FOO&bar=&baz=not+a+time"
120
+ end
106
121
  end
107
122
 
108
123
  def test_transaction
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-parser-query_string
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshihara
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-06 00:00:00.000000000 Z
12
+ date: 2015-10-20 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ name: addressable
21
+ prerelease: false
22
+ type: :runtime
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
14
28
  - !ruby/object:Gem::Dependency
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements: