immosquare-yaml 1.0.3 → 1.0.5

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
  SHA256:
3
- metadata.gz: 4ad1b77c2a0aa94cccc901f2095b51481bcb225a9930c863aab7ea5fa49ced69
4
- data.tar.gz: c9cd9777e43963c3d2ff939b60fb1caf76dde884d7d28dee9357f1b9aad646c5
3
+ metadata.gz: '089aa9af3b0755cde4f7f0c20af8590e5bb3229f95384f89da5871c1370842b6'
4
+ data.tar.gz: 2c2c82b7cf2d6ee1a3019f230fc7f9985fb730ea4830c3830191ed92eb423c65
5
5
  SHA512:
6
- metadata.gz: 79952197dbc28d89be6770eff07d3870332050acfd8e7c5897816a006d969d917f9500bc31540457ab43676324c7280a8dae9434033279c4c820bdccde714b87
7
- data.tar.gz: db4d002fcd3086e86fde1b9d718f23223f6476d895a6973b49373798468ec5a1a39083e91f58ab33b410cfe9b39b7655b5dff48541145ece19d4e8edc9f73e18
6
+ metadata.gz: f0552b22304b12ef1ab7b782beab77aee3574a9866158896bbe828d170549c17b33e2070aec99d9b4067d043adc64f74da80182b64c4bc1f8430c67185bbb24e
7
+ data.tar.gz: ee58bca18dae3197b6e8a749c47a627ae8c965906d90625925b42737351532d0c3eda2f74d9b77c985377f1e541eb46e8da86cecf91729702a36a270cb72029e
@@ -138,11 +138,11 @@ module ImmosquareYaml
138
138
  entries.sort_by {|path, _value, file| [path, file.to_s] }
139
139
  elsif options[:with_values]
140
140
  entries.sort_by {|path, _value, file| [path, file.to_s] }
141
- .map {|path, value, _file| [path, value] }
141
+ .map {|path, value, _file| [path, value] }
142
142
  elsif options[:with_file]
143
143
  entries.map {|path, _value, file| [path, file] }
144
- .uniq
145
- .sort_by {|path, file| [path, file.to_s] }
144
+ .uniq
145
+ .sort_by {|path, file| [path, file.to_s] }
146
146
  else
147
147
  entries.map(&:first).uniq.sort
148
148
  end
@@ -8,7 +8,6 @@ module ImmosquareYaml
8
8
  DOUBLE_QUOTE = '"'.freeze
9
9
  DOUBLE_SIMPLE_QUOTE = "''".freeze
10
10
  CUSTOM_SEPARATOR = "_#_#_".freeze
11
- WEIRD_QUOTES_REGEX = /‘|’|“|”|‛|‚|„|‟|#{Regexp.quote(DOUBLE_SIMPLE_QUOTE)}/
12
11
  YML_SPECIAL_CHARS = ["-", "`", "{", "}", "|", "[", "]", ">", ":", "\"", "'", "*", "=", "%", ",", "!", "?", "&", "#", "@"].freeze
13
12
  RESERVED_KEYS = [
14
13
  "yes", "no", "on", "off", "true", "false",
@@ -1,3 +1,3 @@
1
1
  module ImmosquareYaml
2
- VERSION = "1.0.3".freeze
2
+ VERSION = "1.0.5".freeze
3
3
  end
@@ -272,12 +272,12 @@ module ImmosquareYaml
272
272
  ##
273
273
  ## On quote si la valeur contient des caractères qui auraient
274
274
  ## un sens YAML particulier en plain (": ", " #", début par un
275
- ## caractère spécial, fin par ":", mot réservé, espace en bord).
275
+ ## caractère spécial, fin par ":", espace en bord) ou si Psych
276
+ ## lui attribuerait un type implicite différent de String.
276
277
  ##============================================================##
277
278
  def format_scalar_value(value)
278
279
  value = value.to_s
279
280
  value = decode_unicode_escapes(value)
280
- value = value.gsub(WEIRD_QUOTES_REGEX, SIMPLE_QUOTE)
281
281
 
282
282
  ##============================================================##
283
283
  ## On enlève les guillemets parasites éventuels (cas de fichiers
@@ -298,7 +298,8 @@ module ImmosquareYaml
298
298
  value.end_with?(":") ||
299
299
  RESERVED_KEYS.include?(value) ||
300
300
  value.start_with?(SPACE) ||
301
- value.end_with?(SPACE)
301
+ value.end_with?(SPACE) ||
302
+ psych_implicitly_types?(value)
302
303
 
303
304
  return value if !need_quotes
304
305
 
@@ -318,6 +319,15 @@ module ImmosquareYaml
318
319
  end
319
320
  end
320
321
 
322
+ ##============================================================##
323
+ ## Détecte les scalaires plain que Psych convertirait en nombre,
324
+ ## valeur nulle, date ou heure lors du chargement YAML.
325
+ ##============================================================##
326
+ def psych_implicitly_types?(value)
327
+ scanner = Psych::ScalarScanner.new(Psych::ClassLoader.new, :parse_symbols => false)
328
+ !scanner.tokenize(value).is_a?(String)
329
+ end
330
+
321
331
  ##============================================================##
322
332
  ## Échappe une string pour la sérialiser en YAML double-quoted.
323
333
  ## On gère \, ", \t et \n. Les newlines réels n'arrivent pas
@@ -344,7 +354,7 @@ module ImmosquareYaml
344
354
  ## qui pouvaient contenir des valeurs avec quotes incluses.
345
355
  ##============================================================##
346
356
  def strip_wrapping_quotes(value)
347
- value = value[1..-2] while (value.start_with?(DOUBLE_QUOTE) && value.end_with?(DOUBLE_QUOTE)) || (value.start_with?(SIMPLE_QUOTE) && value.end_with?(SIMPLE_QUOTE))
357
+ value = value[1..-2] while value.length > 2 && ((value.start_with?(DOUBLE_QUOTE) && value.end_with?(DOUBLE_QUOTE)) || (value.start_with?(SIMPLE_QUOTE) && value.end_with?(SIMPLE_QUOTE)))
348
358
  value
349
359
  end
350
360
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immosquare-yaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - immosquare
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 4.0.11
64
+ rubygems_version: 4.0.23
65
65
  specification_version: 4
66
66
  summary: A YAML parser optimized for translation files.
67
67
  test_files: []