immosquare-yaml 1.0.3 → 1.0.4

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: 18474159a026b7caf6296f284339cd69fc74e3d413cc80135d527873a92db43d
4
+ data.tar.gz: a4e7b2e8193dde12dc218a055e6dd857dfdd5255f70ffdebe38568943ee5ffd0
5
5
  SHA512:
6
- metadata.gz: 79952197dbc28d89be6770eff07d3870332050acfd8e7c5897816a006d969d917f9500bc31540457ab43676324c7280a8dae9434033279c4c820bdccde714b87
7
- data.tar.gz: db4d002fcd3086e86fde1b9d718f23223f6476d895a6973b49373798468ec5a1a39083e91f58ab33b410cfe9b39b7655b5dff48541145ece19d4e8edc9f73e18
6
+ metadata.gz: 3895b71e4cee8091551f0ec75a9e95ecdc4a622c89778dac4bdee06d0abf66146021904b583e4baede6a9f12716532f51669d71355298579ce245561641e55fd
7
+ data.tar.gz: bd33415993538752b14b6c18919c984a5964efc2b800161871393d382908bb25949bcd7445780db51fa66b1786ac3c7a2214ee2ccf74253dc645d7b3a4b33bdd
@@ -1,3 +1,3 @@
1
1
  module ImmosquareYaml
2
- VERSION = "1.0.3".freeze
2
+ VERSION = "1.0.4".freeze
3
3
  end
@@ -272,7 +272,8 @@ 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
@@ -298,7 +299,8 @@ module ImmosquareYaml
298
299
  value.end_with?(":") ||
299
300
  RESERVED_KEYS.include?(value) ||
300
301
  value.start_with?(SPACE) ||
301
- value.end_with?(SPACE)
302
+ value.end_with?(SPACE) ||
303
+ psych_implicitly_types?(value)
302
304
 
303
305
  return value if !need_quotes
304
306
 
@@ -318,6 +320,15 @@ module ImmosquareYaml
318
320
  end
319
321
  end
320
322
 
323
+ ##============================================================##
324
+ ## Détecte les scalaires plain que Psych convertirait en nombre,
325
+ ## valeur nulle, date ou heure lors du chargement YAML.
326
+ ##============================================================##
327
+ def psych_implicitly_types?(value)
328
+ scanner = Psych::ScalarScanner.new(Psych::ClassLoader.new, :parse_symbols => false)
329
+ !scanner.tokenize(value).is_a?(String)
330
+ end
331
+
321
332
  ##============================================================##
322
333
  ## Échappe une string pour la sérialiser en YAML double-quoted.
323
334
  ## On gère \, ", \t et \n. Les newlines réels n'arrivent pas
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.4
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.20
65
65
  specification_version: 4
66
66
  summary: A YAML parser optimized for translation files.
67
67
  test_files: []