Commit 713df6f
committed
fix(pnpm): preserve underscores in package names when stripping peer suffix
Fixes SMO-632. `stripPnpmPeerSuffix` scanned the whole dep path for the
first `(` or `_`, which truncated `http_ece@1.0.0` to `http` and caused
`socket pnpm install` to produce a blocking false-positive malware alert
(`http@0.0.1-security: Known malware (critical; blocked)`) on any project
that (transitively) depends on `http_ece` — e.g. `web-push@3.6.7`.
Customer Rio Transfer was blocked by this; reproducible with:
mkdir /tmp/repro && cd /tmp/repro
echo '{"name":"t","private":true,"dependencies":{"web-push":"3.6.7"}}' > package.json
pnpm install
socket pnpm install --frozen-lockfile
## Fix
`(` and `_` peer separators only appear *after* the version-separating
`@` — semver forbids both characters inside a version, prerelease tag,
or build metadata. Narrow the search to the version-and-beyond portion
of the dep path so package-name underscores are preserved.
Walk-through for the regression case:
`http_ece@1.0.0_web-push@3.6.7`
* scopeOffset=0 (no leading `@`)
* versionAt = indexOf('@', 0) = 8
* tail = `@1.0.0_web-push@3.6.7`, underscore at tail[6]
* slice at 8+6 = 14 → `http_ece@1.0.0` ✓
And the scoped variant:
`@foo/bar_baz@1.0.0_peer@2.0.0`
* scopeOffset=1 (skip leading `@`)
* versionAt = indexOf('@', 1) = 12
* tail = `@1.0.0_peer@2.0.0`, underscore at tail[6]
* slice at 12+6 = 18 → `@foo/bar_baz@1.0.0` ✓
## Tests
Added two `it` blocks with six assertions:
* `preserves underscores inside package names (SMO-632 regression)` —
`http_ece` with no suffix / underscore peer / parenthesized peer.
* `handles scoped packages with underscore names` — `@foo/bar_baz`
variants, proving the scope leader `@` doesn't confuse the
version-separator search.
Also rewrote the "prefers parentheses over underscore" case as
"prefers the earlier separator when both appear" — the new algorithm
picks the earlier separator rather than categorically preferring one,
and the only real-world shape where both appear is `(peer)_legacy`
where `(` is earlier, so the observable outcome is unchanged.1 parent 9fae51f commit 713df6f
2 files changed
Lines changed: 68 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | | - | |
104 | | - | |
105 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
106 | 106 | | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
111 | 112 | | |
112 | | - | |
113 | | - | |
114 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
115 | 116 | | |
116 | 117 | | |
117 | | - | |
| 118 | + | |
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
121 | 122 | | |
122 | | - | |
123 | | - | |
124 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
125 | 148 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
229 | | - | |
| 229 | + | |
| 230 | + | |
230 | 231 | | |
231 | 232 | | |
232 | 233 | | |
233 | 234 | | |
234 | 235 | | |
235 | 236 | | |
236 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
237 | 266 | | |
238 | 267 | | |
239 | 268 | | |
| |||
0 commit comments