Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no-implicit-coercion ESLint rule #1405

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/utils/init/config-manual.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,3 +97,5 @@ async function configManual(ctx, site, repo) {
ctx.exit()
}
}

const SSH_URL_REGEXP = /(ssh:\/\/|[a-zA-Z]*@|[a-zA-Z.].*:(?!\/\/))/
11 changes: 7 additions & 4 deletions src/utils/serve-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 || ''
Expand Down