When `asString` receives `undefined` an exception is thrown
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- javascript, node.js
Direzione di ricerca
Il malfunzionamento è segnalato in lib/serializer.js, in Serializer.asString intorno alle righe 103-113; inizia da lì e rivedi l’issue e la pull request correlate per determinare la semantica prevista di null e undefined. Riproduci il caso di risposta Fastify, aggiungi la coverage per il comportamento scelto e verifica che la risposta array non generi più un errore.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.24.3
Plugin version
5.9.1
Node.js version
20.2.0
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
Ubuntu 22.04.1
Description
Not entirely sure this is a bug, could be intended behavior.
I have an array of stings, however one of the elements is undefined.
['test1', 'test2', 'test3', undefined]
If I return that from a fastify endpoint, asString throws an exception:
TypeError: Cannot read properties of undefined (reading 'toString')
at Serializer.asString (/repo/node_modules/fast-json-stringify/lib/serializer.js:113:19)
at anonymous1 (eval at build (/repo/node_modules/fast-json-stringify/index.js:190:23), <anonymous>:17:28)
at anonymous0 (eval at build (/repo/node_modules/fast-json-stringify/index.js:190:23), <anonymous>:52:19)
at serialize (/repo/node_modules/fastify/lib/reply.js:896:12)
at preSerializationHookEnd (/repo/node_modules/fastify/lib/reply.js:516:17)
at preSerializationHook (/repo/node_modules/fastify/lib/reply.js:500:5)
at Reply.send (/repo/node_modules/fastify/lib/reply.js:204:7)
at /repo/node_modules/fastify/lib/wrapThenable.js:25:15
Possibly related:
https://github.com/fastify/fast-json-stringify/issues/218
https://github.com/fastify/fast-json-stringify/pull/84
Steps to Reproduce
export default async (app: FastifyInstance) => {
app.route({
method: 'GET',
url: '/test',
schema: {
response: {
200: {
type: 'object',
properties: {
status: { type: 'string' },
message: { type: 'string' },
testArray: {
type: 'array',
items: { type: 'string' }
}
}
}
}
},
handler: async () => {
return {
status: 'ok',
message: 'This is a test route',
testArray: ['test1', 'test2', 'test3', undefined]
}
}
})
}
Expected Behavior
It seems that asString will default the input to an empty string if its null.
I can confirm this behavior by sending ['test1', 'test2', 'test3', null] instead. No error is thrown, and my response looks like the following:
{
"status": "ok",
"message": "This is a test route",
"testArray": [
"test1",
"test2",
"test3",
""
]
}
I'm thinking that asString should check for undefined as well. However I understand that this may technically be incorrect because my response schema defines an array of strings, not Array<string | undefined>.
- Lingua principale
- JavaScript
- Stelle
- 3.7k
- Fork
- 245
- Merge medio
- 3g 5h
- PR unite (30g)
- 16
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 fastify/fast-json-stringify
-
benchmark question
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
fastify/fast-json-stringify#782 · 15 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
allOf Fails to Handle Array of if/then as Chained else ConditionsForse già presa @junaidkhan80121 l’ha presa 18 giorni fa. Apertabug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
fastify/fast-json-stringify#778 · 5 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
emit CJS/ESM syntax in standalone mode based on AJV code optionsForse già presa @jaideeppyne l’ha presa 101 giorni fa. Apertafeature request
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
fastify/fast-json-stringify#679 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
feature request
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
fastify/fast-json-stringify#627 · 4 commenti · 3 reazioni ·
I maintainer di solito rispondono entro 2 giorni
-
Support TypedArraysForse già presa @junaidkhan80121 l’ha presa 22 giorni fa. Apertafeature request
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
fastify/fast-json-stringify#626 · 1 commento · 4 reazioni ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di fastify/fast-json-stringify
Issue simili
-
FEATURE REQUEST
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
linuxmint/cinnamon-spices-applets#9356 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
needs-triage Platform(Default)
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
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 63/100
I maintainer di solito rispondono entro 1 giorno