Skip to content

Commit

Permalink
Add no-implicit-coercion ESLint rule (#1405)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored Oct 20, 2020
1 parent 158529a commit 102df62
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
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

0 comments on commit 102df62

Please sign in to comment.