Skip to content

Commit

Permalink
fix: safer regex
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Mar 14, 2022
1 parent cda537d commit abcdb36
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/fixer.js
Expand Up @@ -8,6 +8,8 @@ var extractDescription = require('./extract_description')
var url = require('url')
var typos = require('./typos.json')

var isEmail = str => str.includes('@') && (str.indexOf('@') < str.lastIndexOf('.'))

module.exports = {
// default warning function
warn: function () {},
Expand Down Expand Up @@ -264,9 +266,8 @@ module.exports = {
data.bugs = { url: hosted.bugs() }
}
} else if (data.bugs) {
var emailRe = /^.+@.*\..+$/
if (typeof data.bugs === 'string') {
if (emailRe.test(data.bugs)) {
if (isEmail(data.bugs)) {
data.bugs = { email: data.bugs }
/* eslint-disable-next-line node/no-deprecated-api */
} else if (url.parse(data.bugs).protocol) {
Expand All @@ -287,7 +288,7 @@ module.exports = {
}
}
if (oldBugs.email) {
if (typeof (oldBugs.email) === 'string' && emailRe.test(oldBugs.email)) {
if (typeof (oldBugs.email) === 'string' && isEmail(oldBugs.email)) {
data.bugs.email = oldBugs.email
} else {
this.warn('nonEmailBugsEmailField')
Expand Down Expand Up @@ -399,8 +400,8 @@ function parsePerson (person) {
return person
}
var name = person.match(/^([^(<]+)/)
var url = person.match(/\(([^)]+)\)/)
var email = person.match(/<([^>]+)>/)
var url = person.match(/\(([^()]+)\)/)
var email = person.match(/<([^<>]+)>/)
var obj = {}
if (name && name[0].trim()) {
obj.name = name[0].trim()
Expand Down

0 comments on commit abcdb36

Please sign in to comment.