mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-07 18:01:42 +00:00
guard numeric casts for postgres text fields
This commit is contained in:
parent
15d2715a74
commit
8b3f67b7c9
4 changed files with 42 additions and 25 deletions
|
|
@ -8,7 +8,9 @@ const {
|
|||
jsonArrayContainsValue,
|
||||
jsonArrayExpand,
|
||||
jsonPathText,
|
||||
jsonPathNumber
|
||||
jsonPathNumber,
|
||||
safeTextToDoubleExpression,
|
||||
safeTextToIntegerExpression
|
||||
} = require('../../../server/utils/sqlDialectHelpers')
|
||||
|
||||
const sqlite = {
|
||||
|
|
@ -55,4 +57,12 @@ describe('sqlDialectHelpers', () => {
|
|||
expect(jsonPathNumber('payload', ['duration'], sqlite)).to.equal("json_extract(payload, '$.duration')")
|
||||
expect(jsonPathNumber('payload', ['duration'], postgres)).to.equal("NULLIF(payload::jsonb #>> '{duration}', '')::double precision")
|
||||
})
|
||||
|
||||
it('should generate safe numeric cast expressions for sequence-like text', () => {
|
||||
expect(safeTextToDoubleExpression('sequence', sqlite)).to.equal('CAST(sequence AS FLOAT)')
|
||||
expect(safeTextToDoubleExpression('"bookSeries"."sequence"', postgres)).to.equal("CASE WHEN BTRIM(\"bookSeries\".\"sequence\") ~ '^[+-]?(?:\\d+\\.?\\d*|\\.\\d+)$' THEN BTRIM(\"bookSeries\".\"sequence\")::double precision ELSE NULL END")
|
||||
|
||||
expect(safeTextToIntegerExpression('publishedYear', sqlite)).to.equal('CAST(publishedYear AS INTEGER)')
|
||||
expect(safeTextToIntegerExpression('book.publishedYear', postgres)).to.equal("CASE WHEN BTRIM(book.publishedYear) ~ '^[+-]?\\d+$' THEN BTRIM(book.publishedYear)::integer ELSE NULL END")
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue