Skip to content

Commit

Permalink
fix: support Node 16, workaround pipeline bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Oct 26, 2021
1 parent c82ac8f commit 3640c12
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
CC_TEST_REPORTER_ID: de1dd499aa47f47e03c811b848134442d267f451ac39e2bf6b242c7ad0fd8e28
steps:
- { uses: actions/checkout@v2, with: { persist-credentials: false } }
- { uses: actions/setup-node@v2, with: { node-version: 14, cache: 'yarn' } }
- { uses: actions/setup-node@v2, with: { node-version: 16, cache: 'yarn' } }

- name: deps
run: yarn --frozen-lockfile
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
env: { NODE_OPTIONS: '--max-old-space-size=3200' }
steps:
- { uses: actions/checkout@v2, with: { persist-credentials: false } }
- { uses: actions/setup-node@v2, with: { node-version: 14, cache: 'yarn' } }
- { uses: actions/setup-node@v2, with: { node-version: 16, cache: 'yarn' } }
- { name: yarn, run: yarn --frozen-lockfile }

- name: docs-build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
env: { NODE_OPTIONS: '--max-old-space-size=3200' }
steps:
- { uses: actions/checkout@v2, with: { persist-credentials: true } }
- { uses: actions/setup-node@v2, with: { node-version: 14, cache: 'yarn' } }
- { uses: actions/setup-node@v2, with: { node-version: 16, cache: 'yarn' } }

# Cache for npm/npx in ~/.npm
- uses: actions/cache@v2
Expand Down
11 changes: 10 additions & 1 deletion src/stream/pipeline/pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { pipeline } from 'stream'
import { promisify } from 'util'

type AnyStream = NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream

/**
* Promisified stream.pipeline()
*/
export const _pipeline = promisify(pipeline)
export let _pipeline = promisify(pipeline)

// Workaround https://github.com/nodejs/node/issues/40191
// todo: remove it when fix is released in 16.x and in AppEngine 16.x
if (process.version > 'v16.13') {
const { pipeline } = require('stream/promises')
_pipeline = ((streams: AnyStream[]) => pipeline(...streams)) as any
}
6 changes: 4 additions & 2 deletions src/validation/joi/string.extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,16 @@ export function stringExtensions(joi: typeof Joi): Extension {
],
validate(v: string, helpers, args: JoiStripHTMLOptions) {
// console.log('!!! stripHTML', args, v)
const { strict } = args

const r = sanitize(v, {
allowedTags: [], // no html tags allowed at all
// disallowedTagsMode: 'discard' // discard is default
parser: {
decodeEntities: false, // prevent decoding/changing of &<>"'
},
})

if (strict && r !== v) {
if (args.strict && r !== v) {
return helpers.error('string.stripHTML', args)
}

Expand Down
3 changes: 2 additions & 1 deletion src/validation/joi/stripHTML.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ test.each([
'yo % xo %% xo !@#$%^',
'la\nla\nla',
'a + b == c',
// `"Bread" & 'Salt', a < b, b > a`,
])('happy case: nothing to strip: %s', v => {
const schema = stringSchema.stripHTML({ strict: true }).optional()
const schema = stringSchema.stripHTML({ strict: false }).optional()

const r = validate(v, schema)

Expand Down

0 comments on commit 3640c12

Please sign in to comment.