Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
20 lines
633 B
Plaintext
20 lines
633 B
Plaintext
import { APIError } from 'payload';
|
|
export const SAFE_STRING_REGEX = /^[\w @.\-+:]*$/;
|
|
export const escapeSQLValue = (value)=>{
|
|
if (value === null) {
|
|
return null;
|
|
}
|
|
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
return value;
|
|
}
|
|
if (typeof value !== 'string') {
|
|
throw new Error('Invalid value type');
|
|
}
|
|
if (!SAFE_STRING_REGEX.test(value)) {
|
|
throw new APIError(`${value} is not allowed as a JSON query value`, 400);
|
|
}
|
|
const escaped = value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
return escaped;
|
|
};
|
|
|
|
//# sourceMappingURL=escapeSQLValue.js.map |