mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-15 00:09:38 +00:00
Fix codeQL failures
This commit is contained in:
parent
ce4ff4f894
commit
888190a6be
3 changed files with 37 additions and 14 deletions
|
|
@ -277,3 +277,22 @@ module.exports.timestampToSeconds = (timestamp) => {
|
|||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely extracts a query parameter as a string, rejecting arrays to prevent type confusion
|
||||
* Express query parameters can be arrays if the same parameter appears multiple times
|
||||
* @example ?author=Smith => "Smith"
|
||||
* @example ?author=Smith&author=Jones => null (array detected)
|
||||
*
|
||||
* @param {any} value - Query parameter value
|
||||
* @param {string} defaultValue - Default value if undefined/null
|
||||
* @returns {string|null} String value or null if invalid (array)
|
||||
*/
|
||||
module.exports.getQueryParamAsString = (value, defaultValue = '') => {
|
||||
// Explicitly reject arrays to prevent type confusion
|
||||
if (Array.isArray(value)) {
|
||||
return null
|
||||
}
|
||||
// Return default for undefined/null, otherwise return the value
|
||||
return value == null ? defaultValue : value
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue