xsv 1.1.1 → 1.2.0

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
  SHA256:
3
- metadata.gz: b2cc530ad96a5351ea6ab8a8b9d0f2ee9df0e1827a98e4244f239b3658bc2145
4
- data.tar.gz: e286d74163ea3524dfcbd92553c0c4254b667e4ea13adae7468c0d1dc4c8089b
3
+ metadata.gz: 58e5d405e39f42d0e5287d47dd65c65b39a0ab5a2fc7fde3fd85c7211469e6e1
4
+ data.tar.gz: 7100a73ce192536f81a34ffbb1b431a793edf9cb71c1612a547a64a686a8330f
5
5
  SHA512:
6
- metadata.gz: a89e58bc0447ecbd2eefdd81fe978a5e38438296bcce9dbf18b4dbc3fea5d5740016e35237d229fbab8201bb0e71b208ca66858c9d61e85f4d31d729e9048054
7
- data.tar.gz: 45ddf90be0abe97dcd8aac6b08b9daeac2f68f7634062655efee6f59fbef50c6aad3eb69a461b4f7fcf9dd2751fa735de82e9a0821ec18d2f45cb4bada591698
6
+ metadata.gz: 3b8fcbab2e2aa1f02dc0b51051a9b60dd2518b18b72007c2f3e77fa99248e864069d54b0bb43d783f8bb6ef79b6c2504c8cd05c244a2e9c85cddb882de224556
7
+ data.tar.gz: 3ec5120d8b6e365996985c75f4c291e3f4805e9876fd93ae2dfe071c5bd69ad751677cf71121ac23f6e9bed75ab80296b12346d79696cb6105974345d289bb7e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Xsv Changelog
2
2
 
3
+ ## 1.2.0 2023-01-01
4
+
5
+ **This release contains the following minor breaking changes**
6
+
7
+ - Raise an error when entering hash mode on a sheet with duplicate headers to prevent unintentional behaviour (fixes #44)
8
+ - Xsv now returns frozen strings to further improve performance. This means it's no longer possible to call mutating methods on strings read from worksheets without unfreezing them first.
9
+ - Unescape all HTML entities in XML characters (thanks @til)
10
+
3
11
  ## 1.1.1 2022-04-01
4
12
 
5
13
  - Improve compatibility with files generated by the Open XML SDK (#40)
@@ -119,4 +127,4 @@ Fix a Gemfile small Gemfile issue that broke the 0.3.3 and 0.3.4 releases
119
127
 
120
128
  ## 0.3.3 - 2020-03-02
121
129
 
122
- Intial version with a changelog and reasonably complete YARD documentation.
130
+ Initial version with a changelog and reasonably complete YARD documentation.
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # Xsv .xlsx reader
2
2
 
3
3
 
4
- [![Test badge](https://img.shields.io/github/workflow/status/martijn/xsv/Ruby/main)](https://github.com/martijn/xsv/actions/workflows/ruby.yml)
4
+
5
+ [![Test badge](https://img.shields.io/github/actions/workflow/status/martijn/xsv/ruby.yml?branch=main)](https://github.com/martijn/xsv/actions/workflows/ruby.yml)
5
6
  [![Codecov badge](https://img.shields.io/codecov/c/github/martijn/xsv/main)](https://app.codecov.io/gh/martijn/xsv)
6
7
  [![Yard Docs badge](http://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/github/martijn/xsv)
7
8
  [![Gem Version badge](https://badge.fury.io/rb/xsv.svg)](https://badge.fury.io/rb/xsv)
@@ -36,10 +37,9 @@ Or install it yourself as:
36
37
 
37
38
  $ gem install xsv
38
39
 
39
- Xsv targets ruby >= 2.5 and has a just single dependency, `rubyzip`. It has been
40
- tested successfully with MRI, JRuby, and TruffleRuby. Due to the lack of
41
- native extensions should work well in multi-threaded environments or in Ractor
42
- when that becomes stable.
40
+ Xsv targets ruby >= 2.6 and has a just single dependency, `rubyzip`. It has been
41
+ tested successfully with MRI, JRuby, and TruffleRuby. It has no native extensions
42
+ and is designed to be thread-safe.
43
43
 
44
44
  ## Usage
45
45
 
@@ -85,8 +85,11 @@ sheet.parse_headers!
85
85
  sheet[0] # => {"header1" => "value1", "header2" => "value2"}
86
86
  ```
87
87
 
88
- Be aware that hash mode will lead to unpredictable results if the worksheet
89
- has multiple columns with the same header. `Xsv::Sheet` implements `Enumerable` so along with `#each`
88
+ Because of the way Ruby hashes work will raise `Xsv::DuplicateHeaders` if it detects
89
+ duplicate values in the header row when calling `#parse_headers!` or when opening
90
+ a workbook with `parse_headers: true`.
91
+
92
+ `Xsv::Sheet` implements `Enumerable` so along with `#each`
90
93
  you can call methods like `#first`, `#filter`/`#select`, and `#map` on it.
91
94
 
92
95
  ### Opening a string or buffer instead of filename
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "cgi"
4
+
3
5
  module Xsv
4
6
  class SaxParser
5
7
  ATTR_REGEX = /((\p{Alnum}+)="(.*?)")/mn
@@ -36,14 +38,7 @@ module Xsv
36
38
  chars = pbuf.slice!(0, o + 1).chop!.force_encoding("utf-8")
37
39
 
38
40
  if responds_to_characters && !chars.empty?
39
- if chars.index("&")
40
- chars.gsub!("&", "&")
41
- chars.gsub!("'", "'")
42
- chars.gsub!(">", ">")
43
- chars.gsub!("&lt;", "<")
44
- chars.gsub!("&quot;", '"')
45
- end
46
- characters(chars)
41
+ characters(CGI.unescapeHTML(chars))
47
42
  end
48
43
 
49
44
  state = :look_end
@@ -6,7 +6,7 @@ module Xsv
6
6
  class SharedStringsParser < SaxParser
7
7
  def self.parse(io)
8
8
  strings = []
9
- new { |s| strings << s }.parse(io)
9
+ new { |s| strings << -s }.parse(io)
10
10
  strings
11
11
  end
12
12
 
data/lib/xsv/sheet.rb CHANGED
@@ -83,6 +83,12 @@ module Xsv
83
83
  # @return [self]
84
84
  def parse_headers!
85
85
  @headers = parse_headers
86
+
87
+ # Check for duplicate headers, but don't care about nil columns
88
+ if (duplicate_header = @headers.detect { |h| @headers.count(h) > 1 })
89
+ raise Xsv::DuplicateHeaders, "Duplicate header '#{duplicate_header}' found, consider parsing this sheet in array mode."
90
+ end
91
+
86
92
  @mode = :hash
87
93
 
88
94
  self
@@ -85,7 +85,7 @@ module Xsv
85
85
  when "s"
86
86
  @workbook.shared_strings[@current_value.to_i]
87
87
  when "str", "inlineStr"
88
- @current_value.strip
88
+ -@current_value.strip
89
89
  when "e" # N/A
90
90
  nil
91
91
  when nil, "n"
data/lib/xsv/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Xsv
4
- VERSION = "1.1.1"
4
+ VERSION = "1.2.0"
5
5
  end
data/lib/xsv.rb CHANGED
@@ -21,6 +21,8 @@ require "xsv/workbook"
21
21
  module Xsv
22
22
  class Error < StandardError; end
23
23
 
24
+ class DuplicateHeaders < StandardError; end
25
+
24
26
  # An AssertionFailed error indicates an unexpected condition, meaning a bug
25
27
  # or misinterpreted .xlsx document
26
28
  class AssertionFailed < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xsv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martijn Storck
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-01 00:00:00.000000000 Z
11
+ date: 2023-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip