travis-conditions 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b6d3e53b4b901ce98eba3163f1032654784961c
4
- data.tar.gz: d28a8be8838b6db1d8d6ce29ff51e592dbb60f43
3
+ metadata.gz: 792a4640727f5262342fd6970a660617f5716c68
4
+ data.tar.gz: fe13ae1b89ad26522014b5fc95d383f09f1ca3a5
5
5
  SHA512:
6
- metadata.gz: 518227b13beb67aa1fd7853de9fb51a398ead71f1d09ab40724299cd3e25b74d062c36a7c2045115b0804a780f65231a100050894edc932098ba81911b6fc23c
7
- data.tar.gz: 22607b55555edf9f45f0b3ca9c2849717fd1d4cf36ca7a36f9939d5097fd9ec24a1b250e65cd9e9c290b9607cee5be7bbcea5bda04237834711cf03f93604600
6
+ metadata.gz: 1303ea01cbc8f80e19279b5e620ce82812d199f9238247b934250ba1d233497942f4bbbb02ff86a401915a8a59b9fd57e4ff32e0a9f50af742a35a410c2df3f4
7
+ data.tar.gz: 0e34fc4489a9b7ab9ee26364c64429adc830b23fd654a066041b13b1d65aab09eee3a2ce52fd8d40bf5fed8502924f536a31f291640241974f64a283b89ff57c
@@ -2,6 +2,9 @@ module Travis
2
2
  module Conditions
3
3
  module V1
4
4
  class Data < Struct.new(:data)
5
+ PAIRS = /((?:\\.|[^= ]+)*)=("(?:\\.|[^"\\]+)*"|(?:\\.|[^ "\\]+)*)/
6
+ QUOTE = /^(["'])(.*)\1$/
7
+
5
8
  def initialize(data)
6
9
  super(normalize(data))
7
10
  end
@@ -55,15 +58,18 @@ module Travis
55
58
  when Hash
56
59
  obj
57
60
  else
58
- Array(obj).map { |obj| split(obj.to_s) }.to_h
61
+ Array(obj).map { |obj| parse(obj.to_s) }.flatten(1).to_h
59
62
  end
60
63
  end
61
64
 
62
- def split(str)
65
+ def parse(str)
63
66
  str = str.strip
64
67
  raise arg_error(str) if str.empty? || !str.include?("=")
65
- lft, rgt = str.split('=', 2)
66
- [lft, cast(rgt)]
68
+ str.scan(PAIRS).map { |lft, rgt| [lft, cast(unquote(rgt))] }
69
+ end
70
+
71
+ def unquote(str)
72
+ QUOTE =~ str && $2 || str
67
73
  end
68
74
 
69
75
  def arg_error(arg)
@@ -1,5 +1,5 @@
1
1
  module Travis
2
2
  module Conditions
3
- VERSION = '1.0.1'
3
+ VERSION = '1.0.2'
4
4
  end
5
5
  end
data/spec/v1/data_spec.rb CHANGED
@@ -13,9 +13,23 @@ describe Travis::Conditions::V1::Data do
13
13
  end
14
14
 
15
15
  describe 'given an env array' do
16
- let(:env) { ['foo=FOO'] }
17
- it { expect(subject.env(:foo)).to eq 'FOO' }
18
- it { expect(subject.env('foo')).to eq 'FOO' }
16
+ describe 'with a single var' do
17
+ let(:env) { ['foo=FOO'] }
18
+ it { expect(subject.env(:foo)).to eq 'FOO' }
19
+ it { expect(subject.env('foo')).to eq 'FOO' }
20
+ end
21
+
22
+ describe 'with several vars on one string' do
23
+ let(:env) { ['foo=FOO bar=BAR'] }
24
+ it { expect(subject.env(:foo)).to eq 'FOO' }
25
+ it { expect(subject.env(:bar)).to eq 'BAR' }
26
+ end
27
+
28
+ describe 'with quoted vars' do
29
+ let(:env) { ['foo="FOO BAR" bar="BAR BAZ"'] }
30
+ it { expect(subject.env(:foo)).to eq 'FOO BAR' }
31
+ it { expect(subject.env(:bar)).to eq 'BAR BAZ' }
32
+ end
19
33
  end
20
34
 
21
35
  describe 'given a string without an = it raises an ArgumentError' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: travis-conditions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis CI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-28 00:00:00.000000000 Z
11
+ date: 2018-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet