use regex test instead of match when only bool needed

This commit is contained in:
Nate Stemen 2018-08-27 14:25:01 -04:00
parent 2dcd2339ed
commit ebea8a8633
21 changed files with 119 additions and 123 deletions

View file

@ -205,8 +205,8 @@ module.exports = AuthenticationController =
value = if Object.keys(req.query).length > 0 then "#{req.path}?#{querystring.stringify(req.query)}" else "#{req.path}"
if (
req.session? &&
!value.match(new RegExp('^\/(socket.io|js|stylesheets|img)\/.*$')) &&
!value.match(new RegExp('^.*\.(png|jpeg|svg)$'))
!/^\/(socket.io|js|stylesheets|img)\/.*$/.test(value) &&
!/^.*\.(png|jpeg|svg)$/.test(value)
)
req.session.postLoginRedirect = value

View file

@ -262,7 +262,7 @@ module.exports = CompileController =
if req.query?.pdfng
newHeaders = {}
for h, v of req.headers
newHeaders[h] = req.headers[h] if h.match /^(If-|Range)/i
newHeaders[h] = req.headers[h] if /^(If-|Range)/i.test(h)
options.headers = newHeaders
proxy = request(options)
proxy.pipe(res)

View file

@ -80,7 +80,7 @@ module.exports = ProjectFileAgent = {
path: source_entity_path
}, (err, entity, type) ->
if err?
if err.toString().match(/^not found.*/)
if /^not found.*/.test(err.toString())
err = new SourceFileNotFoundError()
return callback(err)
callback(null, project, entity, type)

View file

@ -50,7 +50,7 @@ module.exports = UrlAgent = {
callback(null, readStream)
_prependHttpIfNeeded: (url) ->
if !url.match('://')
if !/:///.test(url)
url = 'http://' + url
return url

View file

@ -462,6 +462,6 @@ THEME_LIST = []
do generateThemeList = () ->
files = fs.readdirSync __dirname + '/../../../../public/js/' + PackageVersions.lib('ace')
for file in files
if file.slice(-2) == "js" and file.match(/^theme-/)
if file.slice(-2) == "js" and /^theme-/.test(file)
cleanName = file.slice(0,-3).slice(6)
THEME_LIST.push cleanName

View file

@ -294,7 +294,7 @@ module.exports = ProjectEntityMongoUpdateHandler = self =
# in the destination folder
self._checkValidElementName destEntity, entity.name, (err)->
return callback(err) if err?
if entityType.match(/folder/)
if /folder/.test(entityType)
logger.log destFolderPath: destFolderPath.fileSystem, folderPath: entityPath.fileSystem, "checking folder is not moving into child folder"
isNestedFolder = destFolderPath.fileSystem.slice(0, entityPath.fileSystem.length) == entityPath.fileSystem
if isNestedFolder

View file

@ -20,8 +20,8 @@ module.exports = ProjectRootDocManager =
# Previously /.*\\documentclass/ would totally lock up on lines of 500kb (data text files :()
# This regex will only look from the start of the line, including whitespace so will return quickly
# regardless of line length.
match = line.match /^\s*\\documentclass/
isRootDoc = Path.extname(path).match(/\.R?tex$/) and match
match = /^\s*\\documentclass/.test(line)
isRootDoc = /\.R?tex$/.test(Path.extname(path)) and match
if isRootDoc
rootDocId = doc?._id
cb(rootDocId)
@ -31,4 +31,3 @@ module.exports = ProjectRootDocManager =
ProjectEntityUpdateHandler.setRootDoc project_id, root_doc_id, callback
else
callback()

View file

@ -63,9 +63,9 @@ load = () ->
isCleanFilename: (filename) ->
return SafePath.isAllowedLength(filename) &&
not filename.match(BADCHAR_RX) &&
not filename.match(BADFILE_RX) &&
not filename.match(BLOCKEDFILE_RX)
!BADCHAR_RX.test(filename) &&
!BADFILE_RX.test(filename) &&
!BLOCKEDFILE_RX.test(filename)
isAllowedLength: (pathname) ->
return pathname.length > 0 && pathname.length <= MAX_PATH

View file

@ -22,9 +22,9 @@ module.exports = UserController =
getPersonalInfo: (req, res, next = (error) ->) ->
{user_id} = req.params
if user_id.match(/^\d+$/)
if /^\d+$/.test(user_id)
query = { "overleaf.id": parseInt(user_id, 10) }
else if user_id.match(/^[a-f0-9]{24}$/)
else if /^[a-f0-9]{24}$/.test(user_id)
query = { _id: ObjectId(user_id) }
else
return res.send(400)

View file

@ -198,9 +198,9 @@ define [
userAgent = navigator.userAgent
ide.browserIsSafari = (
userAgent &&
userAgent.match(/.*Safari\/.*/) &&
!userAgent.match(/.*Chrome\/.*/) &&
!userAgent.match(/.*Chromium\/.*/)
/.*Safari\/.*/.test(userAgent) &&
!/.*Chrome\/.*/.test(userAgent) &&
!/.*Chromium\/.*/.test(userAgent) &&
)
catch err
console.error err

View file

@ -62,10 +62,10 @@ load = () ->
return filename
isCleanFilename: (filename) ->
return SafePath.isAllowedLength(filename) &&
not filename.match(BADCHAR_RX) &&
not filename.match(BADFILE_RX) &&
not filename.match(BLOCKEDFILE_RX)
return SafePath.isAllowedLength(filename) and
not BADCHAR_RX.test(filename) and
not BADFILE_RX.test(filename) and
not BLOCKEDFILE_RX.test(filename)
isAllowedLength: (pathname) ->
return pathname.length > 0 && pathname.length <= MAX_PATH

View file

@ -131,12 +131,12 @@ define [
message = error
else
message = ""
if message.match "maxDocLength"
if /maxDocLength/.test(message)
@ide.showGenericMessageModal(
"Document Too Long"
"Sorry, this file is too long to be edited manually. Please upload it directly."
)
else if message.match "too many comments or tracked changes"
else if /too many comments or tracked changes/.test(message)
@ide.showGenericMessageModal(
"Too many comments or tracked changes"
"Sorry, this file has too many comments or tracked changes. Please try accepting or rejecting some existing changes, or resolving and deleting some comments."

View file

@ -416,10 +416,10 @@ define [
# see if we can lookup a suitable mode from ace
# but fall back to text by default
try
if scope.fileName.match(/\.(Rtex|bbl)$/i)
if /\.(Rtex|bbl)$/i.test(scope.fileName)
# recognise Rtex and bbl as latex
mode = "ace/mode/latex"
else if scope.fileName.match(/\.(sty|cls|clo)$/)
else if /\.(sty|cls|clo)$/.test(scope.fileName)
# recognise some common files as tex
mode = "ace/mode/tex"
else
@ -437,7 +437,7 @@ define [
session.setUseWrapMode(true)
# use syntax validation only when explicitly set
if scope.syntaxValidation? and syntaxValidationEnabled and !scope.fileName.match(/\.bib$/)
if scope.syntaxValidation? and syntaxValidationEnabled and !/\.bib$/.test(scope.fileName)
session.setOption("useWorker", scope.syntaxValidation);
# now attach session to editor

View file

@ -162,12 +162,12 @@ define [
cursorPosition = @editor.getCursorPosition()
end = change.end
{lineUpToCursor, commandFragment} = Helpers.getContext(@editor, end)
if lineUpToCursor.match(/.*((?![\\]).|^)%.*/)
if /.*((?![\\]).|^)%.*/.test(lineUpToCursor)
return
lastCharIsBackslash = lineUpToCursor.slice(-1) == "\\"
lastTwoChars = lineUpToCursor.slice(-2)
# Don't offer autocomplete on double-backslash, backslash-colon, etc
if lastTwoChars.match(/^\\[^a-zA-Z]$/)
if /^\\[^a-zA-Z]$/.test(lastTwoChars)
@editor?.completer?.detach?()
return
# Check that this change was made by us, not a collaborator
@ -184,8 +184,8 @@ define [
, 0
if (
change.action == "insert" and
change.lines[0].match(/\\(\w+){}/)?[1].match(
/(begin|end|[a-z]*ref|usepackage|[a-z]*cite[a-z]*|input|include)/
/(begin|end|[a-z]*ref|usepackage|[a-z]*cite[a-z]*|input|include)/.test(
change.lines[0].match(/\\(\w+){}/)?[1]
)
)
setTimeout () =>
@ -208,7 +208,7 @@ define [
# If we are in \begin{it|}, then we need to remove the trailing }
# since it will be adding in with the autocomplete of \begin{item}...
if this.completions.filterText.match(/^\\\w+{/) and nextChar == "}"
if /^\\\w+{/.test(this.completions.filterText) and nextChar == "}"
editor.session.remove(range)
# Provide our own `insertMatch` implementation.

View file

@ -393,7 +393,7 @@ define [
console.error "Change doesn't match marker anymore", {change, marker, start, end}
for marker_id, marker of markers
if marker.clazz.match("track-changes")
if /track-changes/.test(marker.clazz)
console.error "Orphaned ace marker", marker
updateFocus: () ->
@ -563,4 +563,3 @@ define [
callout_marker = markers[callout_marker_id]
callout_marker.range.start = start
callout_marker.range.end = start

View file

@ -88,7 +88,7 @@ module.exports = PgDb = (options) ->
client.query sql, values, (error, result) ->
if !error?
callback?()
else if error.toString().match "duplicate key value violates unique constraint"
else if /duplicate key value violates unique constraint/.test(error.toString())
callback? "Document already exists"
else
callback? error?.message

View file

@ -371,7 +371,7 @@ module.exports = Model = (db, options) ->
@create = (docName, type, meta, callback) ->
[meta, callback] = [{}, meta] if typeof meta is 'function'
return callback? 'Invalid document name' if docName.match /\//
return callback? 'Invalid document name' if /\//.test(docName)
return callback? 'Document already exists' if docs[docName]
type = types[type] if typeof type == 'string'
@ -600,4 +600,3 @@ module.exports = Model = (db, options) ->
# Model inherits from EventEmitter.
Model:: = new EventEmitter

View file

@ -349,7 +349,7 @@ define [
qs.clsiserverid = response.clsiServerId
for file in response.outputFiles
if IGNORE_FILES.indexOf(file.path) == -1
isOutputFile = file.path.match(/^output\./)
isOutputFile = /^output\./.test(file.path)
$scope.pdf.outputFiles.push {
# Turn 'output.blg' into 'blg file'.
name: if isOutputFile then "#{file.path.replace(/^output\./, "")} file" else file.path
@ -481,8 +481,7 @@ define [
doc = ide.editorManager.getCurrentDocValue()
return null if !doc?
for line in doc.split("\n")
match = line.match /^[^%]*\\documentclass/
if match
if /^[^%]*\\documentclass/.test(line)
return ide.editorManager.getCurrentDocId()
return null

View file

@ -28,7 +28,7 @@ define [
# TODO need a proper url manipulation library to add to query string
url = $scope.pdfSrc
# add 'pdfng=true' to show that we are using the angular pdfjs viewer
queryStringExists = url.match(/\?/)
queryStringExists = /\?/.test(url)
url = url + (if not queryStringExists then '?' else '&') + 'pdfng=true'
# for isolated compiles, load the pdf on-demand because nobody will overwrite it
onDemandLoading = true
@ -384,7 +384,7 @@ define [
return if error == 'cancelled'
# check if too many retries or file is missing
message = error?.message or error
if scope.loadCount > 3 || message.match(/^Missing PDF/i) || message.match(/^loading/i)
if scope.loadCount > 3 || /^Missing PDF/i.test(message) || /^loading/i.test(message)
scope.$emit 'pdf:error:display'
return
if scope.loadSuccess

View file

@ -28,9 +28,9 @@ define [
# Only show the lines that have a highlighted match
matching_lines = []
for line in lines
if !line.match(/^\[edit\]/)
if !/^\[edit\]/.test(line)
content += line + "\n"
if line.match(/<em>/)
if /<em>/.test(line)
matching_lines.push line
content = matching_lines.join("\n...\n")
result =

View file

@ -27,9 +27,9 @@ define [
# Only show the lines that have a highlighted match
matching_lines = []
for line in lines
if !line.match(/^\[edit\]/)
if !/^\[edit\]/.test(line)
content += line + "\n"
if line.match(/<em>/)
if /<em>/.test(line)
matching_lines.push line
content = matching_lines.join("\n...\n")
result =