zod_rails 0.3.3 → 0.3.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: a3bb629bad6c240427eb327d8516a25e9671c3c89cde6fa3f9abb387e67482b0
4
- data.tar.gz: 68562b20f61dbc7976ed726eafd331c691b3c163ceac2145364b4e4b29bf935c
3
+ metadata.gz: 3fff056b8fe5659f0457c5d3b972d59db1f411abb2608d34a340fedd6066dc5f
4
+ data.tar.gz: c13ea0b418f7ec82797a590e71ac8a574c5dab65c854b2a97632c0e312525b3b
5
5
  SHA512:
6
- metadata.gz: ca1646a86ae4cd04d032f677693ca1ca362ddfd88f29e2c2ced4f4e640f06e98fc26e04645c9e5e385843e5bd52ec95a0bb47d810b16dc557cbd95964f5e9e14
7
- data.tar.gz: 6c2ce4bdd153ddcbe85c31878c6e1a5b172c84570037707d05ab60ba41c54b3f60d0e61924bcb85afcb26f825bacf75ad8cee8fac4fc22f8aa9d13f7fc582711
6
+ metadata.gz: 6c08bf242111a46bf2fcfe940db3775e950044812b43e2131be34dc48d0377a308997357891670f76f280cd6f26b154be85f826add11797b5b008fc6f8b04249
7
+ data.tar.gz: 59b9e915272197431fba2e955a1e78c434e2ec899eb4d692b758068d2610a6138b8a086783a4c4585555f564efa3e3aff9550a739a9b8d040ef35a84d7bacea6
data/CHANGELOG.md CHANGED
@@ -4,6 +4,25 @@ All notable changes to ZodRails are documented here.
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## 0.3.4 - 2026-08-04
8
+
9
+ ### Upgrade Notes
10
+
11
+ - Regenerate committed schemas after upgrading if any model uses `validates :attr, format: { with: ... }` on a column
12
+ that is nullable or has a database default. Those schemas contain a silently corrupted `new RegExp(...)` pattern.
13
+
14
+ ### Fixed
15
+
16
+ - Preserve backslash escaping in generated `new RegExp(...)` patterns. A validation chain was spliced ahead of a
17
+ `.nullable()`, `.nullish()`, or `.optional()` suffix through a `String#sub` replacement string, which expanded the
18
+ chain's backslash sequences: `\\.` collapsed to `\.` and `\\s` to `\s`. The emitted pattern still parsed as valid
19
+ TypeScript but no longer matched the Ruby regexp it came from — most damagingly, the `\z` end anchor degraded from
20
+ `(?![\s\S])` to `(?![sS])`, so `.regex()` began accepting any value with a merely valid prefix. Columns without a
21
+ nullability suffix took a different branch and were unaffected, which is why input schemas were hit far more often
22
+ than response schemas.
23
+ - Preserve backslash sequences inside a `ZOD_RAILS:CUSTOM:IMPORTS` block across regeneration. The same
24
+ replacement-string expansion rewrote hand-authored content the writer is meant to carry over untouched.
25
+
7
26
  ## 0.3.3 - 2026-08-03
8
27
 
9
28
  ### Changed
@@ -48,8 +48,14 @@ module ZodRails
48
48
  result
49
49
  end
50
50
 
51
+ # Concatenate rather than interpolating the preserved block into a `sub`
52
+ # replacement string, which would expand any backslash sequence the author
53
+ # wrote inside their custom imports.
51
54
  def insert_imports_block(content, imports_block)
52
- content.sub(ZOD_IMPORT_RE, "\\1\n#{imports_block}")
55
+ match = content.match(ZOD_IMPORT_RE)
56
+ return content unless match
57
+
58
+ "#{match.pre_match}#{match[0]}\n#{imports_block}#{match.post_match}"
53
59
  end
54
60
 
55
61
  def append_tail_block(content, tail_block)
@@ -110,14 +110,16 @@ module ZodRails
110
110
  insert_validation_chain(base_type, validation_chain)
111
111
  end
112
112
 
113
+ # Splice by concatenation, never via a `sub` replacement string: those expand
114
+ # backslash sequences (`\\`, `\1`, `\&`), which silently corrupts the escaping
115
+ # in a generated `new RegExp("...")` literal.
113
116
  def insert_validation_chain(base_type, validation_chain)
114
117
  return base_type if validation_chain.empty?
115
118
 
116
- if (match = base_type.match(NULLABILITY_SUFFIX_RE))
117
- base_type.sub(NULLABILITY_SUFFIX_RE, "#{validation_chain}#{match[0]}")
118
- else
119
- "#{base_type}#{validation_chain}"
120
- end
119
+ match = base_type.match(NULLABILITY_SUFFIX_RE)
120
+ return "#{base_type}#{validation_chain}" unless match
121
+
122
+ "#{match.pre_match}#{validation_chain}#{match[0]}"
121
123
  end
122
124
 
123
125
  def enum_column?(column_name)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZodRails
4
- VERSION = "0.3.3"
4
+ VERSION = "0.3.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zod_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Kelly
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-08-03 00:00:00.000000000 Z
11
+ date: 2026-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord