[BUG] npm pkg delete removes the first array item for a nonexistent property
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 83/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, node.js
- Ambito
- cli
Direzione di ricerca
L’issue rimanda a lib/utils/queryable.js, in particolare al percorso di eliminazione alle righe 197–204. Leggi quel codice e segui come Queryable.delete() gestisce una chiave stringa quando il suo elemento genitore è un array; confrontalo con il comportamento segnalato di keywords[1]. Il lavoro è completato quando l’eliminazione di una proprietà dell’array inesistente lascia l’array invariato o rifiuta il percorso senza salvare, mentre l’eliminazione di un indice valido continua a funzionare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
is there an existing issue for this?
- I have searched the existing issues
this issue exists in the latest npm version
- I am using the latest npm
this is not just a request to bump a dependency for a CVE
- This is not solely a request to bump a dependency for a CVE
current behavior
npm pkg delete keywords.missing removes the first keyword.. even though there is no missing property. the command exits 0 without a warning.
with "keywords": ["alpha", "beta"], the result is "keywords": ["beta"].
keywords.beta does the same thing.. it removes "alpha", not the value named "beta". contributors.missing also removes the first contributor when contributors is an array of objects.
expected behavior
a nonexistent property should not cause an unrelated array item to be deleted.. either leave the array unchanged or reject the path without saving changes.
steps to reproduce
mkdir npm-pkg-delete-repro
cd npm-pkg-delete-repro
echo '{"name":"pkg-delete-repro","version":"1.0.0","keywords":["alpha","beta"]}' > package.json
npm pkg delete keywords.missing
cat package.json
result:
{
"name": "pkg-delete-repro",
"version": "1.0.0",
"keywords": [
"beta"
]
}
resetting the fixture and running npm pkg delete 'keywords[1]' correctly removes "beta". deleting a missing property from an object.. such as scripts.missing.. leaves its existing properties alone.
in lib/utils/queryable.js, the delete path calls _data.splice(_key, 1) whenever the parent is an array. a nonnumeric key remains a string.. splice() coerces it to NaN and treats that as index 0.
environment
- npm: 12.2.0, the current
latestregistry tag - Node.js: v24.21.0
- macOS 26.4, arm64
- reproduced with empty user and global npm config files
also reproduced with npm 11.19.0. the current latest branch's Queryable.delete() reproduces it directly too.. checked at ae98c62586b6fea44114f72e249e246a2981de70.
- Lingua principale
- JavaScript
- Stelle
- 10.2k
- Fork
- 4.9k
- Merge medio
- 5g 4h
- PR unite (30g)
- 17
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di npm/cli
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 2 giorni
-
create node pr: Node.js 20 deprecation & `DEP0040` warnings loggedForse già presa @lazerg l’ha presa 26 giorni fa. ApertaEngineering Priority 1
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
I maintainer di solito rispondono entro 2 giorni
-
Engineering Priority 2
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 2 giorni
-
`npm audit signatures` does not report how many packages it skipped for want of registry keysForse già presa @greenlincoln05 l’ha presa 22 giorni fa. ApertaPriority 3
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 2 giorni
-
[BUG] E401 error message does not use the configured registryForse già presa @toufiq-dev l’ha presa 25 giorni fa. ApertaBug Priority 3
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 2 giorni
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
highcharts/highcharts-react#594 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno