diff --git a/.eslintrc.js b/.eslintrc.js index a413fed5f9c..32d4d8cb511 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -29,6 +29,7 @@ module.exports = { 'func-name-matching': [2, { considerPropertyDescriptor: true }], 'multiline-comment-style': [2, 'separate-lines'], 'no-else-return': [2, { allowElseIf: false }], + 'no-implicit-coercion': 2, 'no-var': 2, // This version of eslint-plugin-unicorn requires Node 10 diff --git a/src/utils/init/config-manual.js b/src/utils/init/config-manual.js index 500706f480a..83d7b09be3a 100644 --- a/src/utils/init/config-manual.js +++ b/src/utils/init/config-manual.js @@ -69,8 +69,7 @@ async function configManual(ctx, site, repo) { name: 'repoPath', message: 'The SSH URL of the remote git repo:', default: repo.repo_path, - validate: (url) => - !!url.match(/(ssh:\/\/|[a-zA-Z]*@|[a-zA-Z.].*:(?!\/\/))/) || 'The URL provided does not use the SSH protocol', + validate: (url) => SSH_URL_REGEXP.test(url) || 'The URL provided does not use the SSH protocol', }, ]) repo.repo_path = repoPath @@ -98,3 +97,5 @@ async function configManual(ctx, site, repo) { ctx.exit() } } + +const SSH_URL_REGEXP = /(ssh:\/\/|[a-zA-Z]*@|[a-zA-Z.].*:(?!\/\/))/ diff --git a/src/utils/serve-functions.js b/src/utils/serve-functions.js index ff2f235e7eb..a6e40f44ca6 100644 --- a/src/utils/serve-functions.js +++ b/src/utils/serve-functions.js @@ -99,6 +99,12 @@ const clearCache = (action) => (path) => { console.log(`${NETLIFYDEVLOG} ${path} ${action}, successfully reloaded!`) } +const shouldBase64Encode = function (contentType) { + return Boolean(contentType) && BASE_64_MIME_REGEXP.test(contentType) +} + +const BASE_64_MIME_REGEXP = /image|audio|video|application\/pdf|application\/zip|applicaton\/octet-stream/i + function createHandler(dir) { const functions = getFunctions(dir) @@ -125,10 +131,7 @@ function createHandler(dir) { } const { functionPath } = functions[func] - const isBase64Encoded = !!(request.headers['content-type'] || '') - .toLowerCase() - .match(/image|audio|video|application\/pdf|application\/zip|applicaton\/octet-stream/) - + const isBase64Encoded = shouldBase64Encode(request.headers['content-type']) const body = request.get('content-length') ? request.body.toString(isBase64Encoded ? 'base64' : 'utf8') : undefined let remoteAddress = request.get('x-forwarded-for') || request.connection.remoteAddress || ''