Skip to content

Commit

Permalink
chore(lint): add no-implicit-coercion ESLint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Oct 20, 2020
1 parent b8eabb3 commit fb11aaf
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 fb11aaf

Please sign in to comment.