json_mend 0.2.1 → 0.2.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
  SHA256:
3
- metadata.gz: 9a3bfc54ceae164d2837fbcdf3751e79359397b735693ec990954fee19bfa60e
4
- data.tar.gz: 2dfea1b0a6ada799891385ec4c35a83153005f5b344e23b7a9921c726a94c220
3
+ metadata.gz: 132fa0fa5489f3d26c01bbb256ed9abbc2af84bf5e39da35d3ef2aa62d610154
4
+ data.tar.gz: 3dbf1c1d09ebfdd61a07e51465e3239d7f069de57853c26a540349638fdce4b6
5
5
  SHA512:
6
- metadata.gz: '0592fea3e3859aaafbc6b2508b03de3a54eefd17e4520375ce1163e929ed24be10ad16b2936db2175ec79d9f9f4dd7acbd82ba72b50c3df3ea347ffe8436ded6'
7
- data.tar.gz: 6708504ef9b2c1f68f0bdc1da889c254580a169066d37db99993468f78bcb9c3f8ca351dfaafecbc62780d319c12e51a4536b6da70a589d450ead3f407ed8ea7
6
+ metadata.gz: ce3494e2d0a6c35de7828051050a35a022ecba2659d93d814b455cab38f6bc7c3128ba2751789663e66bd19ac7a8598f63681489705578aa101d9ef543d3fa17
7
+ data.tar.gz: d469f040577069840fb06cfad141793c4a17d6e4113705205e3045ebe3d75669e0b5d190a7221fcc3a8909a5a4217cbb3ad37f9fd0a53d8a4fe855e744fcf528
@@ -1065,6 +1065,9 @@ module JsonMend
1065
1065
  scanned_str = @scanner.scan(regex)
1066
1066
  return nil unless scanned_str
1067
1067
 
1068
+ # Save the original length so we can safely roll back if it's completely invalid
1069
+ original_length = scanned_str.bytesize
1070
+
1068
1071
  # Handle cases where the number ends with an invalid character.
1069
1072
  if !scanned_str.empty? && INVALID_NUMBER_TRAILERS.include?(scanned_str[-1])
1070
1073
  # Do not rewind scanner, simply discard the invalid trailing char (garbage)
@@ -1073,10 +1076,16 @@ module JsonMend
1073
1076
  # e.g. "123-abc"
1074
1077
  elsif peek_char&.match?(/\p{L}/)
1075
1078
  # Roll back the entire scan and re-parse as a string.
1076
- @scanner.pos -= scanned_str.bytesize
1079
+ @scanner.pos -= original_length
1077
1080
  return parse_string
1078
1081
  end
1079
1082
 
1083
+ # Reject non-numbers (e.g., stray periods "." or dashes "-" from LLM conversational text)
1084
+ unless scanned_str.match?(/\d/)
1085
+ @scanner.pos -= original_length
1086
+ return ''
1087
+ end
1088
+
1080
1089
  # Sometimes numbers are followed by a quote, which is garbage
1081
1090
  @scanner.getch if peek_char == '"'
1082
1091
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonMend
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_mend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleksii Vasyliev