Просмотр исходного кода

use regex test instead of match when only bool needed

Nate Stemen 8 лет назад
Родитель
Сommit
ebea8a8633
21 измененных файлов с 119 добавлено и 123 удалено
  1. 2 2
      services/web/app/coffee/Features/Authentication/AuthenticationController.coffee
  2. 1 1
      services/web/app/coffee/Features/Compile/CompileController.coffee
  3. 1 1
      services/web/app/coffee/Features/LinkedFiles/ProjectFileAgent.coffee
  4. 1 1
      services/web/app/coffee/Features/LinkedFiles/UrlAgent.coffee
  5. 1 1
      services/web/app/coffee/Features/Project/ProjectController.coffee
  6. 1 1
      services/web/app/coffee/Features/Project/ProjectEntityMongoUpdateHandler.coffee
  7. 2 3
      services/web/app/coffee/Features/Project/ProjectRootDocManager.coffee
  8. 6 6
      services/web/app/coffee/Features/Project/SafePath.coffee
  9. 2 2
      services/web/app/coffee/Features/User/UserInfoController.coffee
  10. 3 3
      services/web/public/coffee/ide.coffee
  11. 7 7
      services/web/public/coffee/ide/directives/SafePath.coffee
  12. 9 9
      services/web/public/coffee/ide/editor/EditorManager.coffee
  13. 3 3
      services/web/public/coffee/ide/editor/directives/aceEditor.coffee
  14. 5 5
      services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee
  15. 50 51
      services/web/public/coffee/ide/editor/directives/aceEditor/track-changes/TrackChangesManager.coffee
  16. 1 1
      services/web/public/coffee/ide/editor/sharejs/vendor/server/db/pg.coffee
  17. 8 9
      services/web/public/coffee/ide/editor/sharejs/vendor/server/model.coffee
  18. 2 3
      services/web/public/coffee/ide/pdf/controllers/PdfController.coffee
  19. 6 6
      services/web/public/coffee/ide/pdfng/directives/pdfViewer.coffee
  20. 5 5
      services/web/public/coffee/main/learn.coffee
  21. 3 3
      services/web/public/coffee/main/templates.coffee

+ 2 - 2
services/web/app/coffee/Features/Authentication/AuthenticationController.coffee

@@ -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
 

+ 1 - 1
services/web/app/coffee/Features/Compile/CompileController.coffee

@@ -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)

+ 1 - 1
services/web/app/coffee/Features/LinkedFiles/ProjectFileAgent.coffee

@@ -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)

+ 1 - 1
services/web/app/coffee/Features/LinkedFiles/UrlAgent.coffee

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

+ 1 - 1
services/web/app/coffee/Features/Project/ProjectController.coffee

@@ -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

+ 1 - 1
services/web/app/coffee/Features/Project/ProjectEntityMongoUpdateHandler.coffee

@@ -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

+ 2 - 3
services/web/app/coffee/Features/Project/ProjectRootDocManager.coffee

@@ -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()
-

+ 6 - 6
services/web/app/coffee/Features/Project/SafePath.coffee

@@ -1,5 +1,5 @@
 # This file is shared between the frontend and server code of web, so that
-# filename validation is the same in both implementations.  
+# filename validation is the same in both implementations.
 # Both copies must be kept in sync:
 #   app/coffee/Features/Project/SafePath.coffee
 #   public/coffee/ide/directives/SafePath.coffee
@@ -55,7 +55,7 @@ load = () ->
 		clean: (filename) ->
 			filename = filename.replace BADCHAR_RX, '_'
 			# for BADFILE_RX replace any matches with an equal number of underscores
-			filename = filename.replace BADFILE_RX, (match) -> 
+			filename = filename.replace BADFILE_RX, (match) ->
 				return new Array(match.length + 1).join("_")
 			# replace blocked filenames 'prototype' with '@prototype'
 			filename = filename.replace BLOCKEDFILE_RX, "@$1"
@@ -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
@@ -73,4 +73,4 @@ load = () ->
 if define?
 	define [], load
 else
-	module.exports = load()
+	module.exports = load()

+ 2 - 2
services/web/app/coffee/Features/User/UserInfoController.coffee

@@ -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)

+ 3 - 3
services/web/public/coffee/ide.coffee

@@ -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

+ 7 - 7
services/web/public/coffee/ide/directives/SafePath.coffee

@@ -1,5 +1,5 @@
 # This file is shared between the frontend and server code of web, so that
-# filename validation is the same in both implementations.  
+# filename validation is the same in both implementations.
 # Both copies must be kept in sync:
 #   app/coffee/Features/Project/SafePath.coffee
 #   public/coffee/ide/directives/SafePath.coffee
@@ -55,17 +55,17 @@ load = () ->
 		clean: (filename) ->
 			filename = filename.replace BADCHAR_RX, '_'
 			# for BADFILE_RX replace any matches with an equal number of underscores
-			filename = filename.replace BADFILE_RX, (match) -> 
+			filename = filename.replace BADFILE_RX, (match) ->
 				return new Array(match.length + 1).join("_")
 			# replace blocked filenames 'prototype' with '@prototype'
 			filename = filename.replace BLOCKEDFILE_RX, "@$1"
 			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
@@ -73,4 +73,4 @@ load = () ->
 if define?
 	define [], load
 else
-	module.exports = load()
+	module.exports = load()

+ 9 - 9
services/web/public/coffee/ide/editor/EditorManager.coffee

@@ -36,7 +36,7 @@ define [
 
 			@$scope.$on "flush-changes", () =>
 				Document.flushAll()
-			
+
 			@$scope.$watch "editor.wantTrackChanges", (value) =>
 				return if !value?
 				@_syncTrackChangesState(@$scope.editor.sharejs_doc)
@@ -47,7 +47,7 @@ define [
 			@localStorage("editor.mode.#{@$scope.project_id}") == 'rich-text'
 
 		autoOpenDoc: () ->
-			open_doc_id = 
+			open_doc_id =
 				@ide.localStorage("doc.open_id.#{@$scope.project_id}") or
 				@$scope.project.rootDoc_id
 			return if !open_doc_id?
@@ -76,7 +76,7 @@ define [
 					setTimeout () =>
 						@$scope.$broadcast "editor:gotoOffset", options.gotoOffset
 					, 0
-					
+
 
 			if doc.id == @$scope.editor.open_doc_id and !options.forceReopen
 				@$scope.$apply () =>
@@ -97,7 +97,7 @@ define [
 						"Sorry, something went wrong opening this document. Please try again."
 					)
 					return
-				
+
 				@_syncTrackChangesState(sharejs_doc)
 
 				@$scope.$broadcast "doc:opened"
@@ -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."
@@ -165,13 +165,13 @@ define [
 
 		getCurrentDocId: () ->
 			@$scope.editor.open_doc_id
-			
+
 		startIgnoringExternalUpdates: () ->
 			@_ignoreExternalUpdates = true
-			
+
 		stopIgnoringExternalUpdates: () ->
 			@_ignoreExternalUpdates = false
-		
+
 		_syncTimeout: null
 		_syncTrackChangesState: (doc) ->
 			return if !doc?

+ 3 - 3
services/web/public/coffee/ide/editor/directives/aceEditor.coffee

@@ -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

+ 5 - 5
services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee

@@ -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.

+ 50 - 51
services/web/public/coffee/ide/editor/directives/aceEditor/track-changes/TrackChangesManager.coffee

@@ -6,41 +6,41 @@ define [
 ], (_, EventEmitter, ColorManager, AceShareJsCodec) ->
 	class TrackChangesManager
 		Range = ace.require("ace/range").Range
-		
+
 		constructor: (@$scope, @editor, @element) ->
 			window.trackChangesManager ?= @
 
 			@$scope.$watch "trackChanges", (track_changes) =>
 				return if !track_changes?
 				@setTrackChanges(track_changes)
-			
+
 			@$scope.$watch "sharejsDoc", (doc, oldDoc) =>
 				return if !doc?
 				if oldDoc?
 					@disconnectFromDoc(oldDoc)
 				@connectToDoc(doc)
-			
+
 			@$scope.$on "comment:add", (e, thread_id, offset, length) =>
 				@addCommentToSelection(thread_id, offset, length)
 
 			@$scope.$on "comment:select_line", (e) =>
 				@selectLineIfNoSelection()
-			
+
 			@$scope.$on "changes:accept", (e, change_ids) =>
 				@acceptChangeIds(change_ids)
 
 			@$scope.$on "changes:reject", (e, change_ids) =>
 				@rejectChangeIds(change_ids)
-			
+
 			@$scope.$on "comment:remove", (e, comment_id) =>
 				@removeCommentId(comment_id)
-			
+
 			@$scope.$on "comment:resolve_threads", (e, thread_ids) =>
 				@hideCommentsByThreadIds(thread_ids)
-			
+
 			@$scope.$on "comment:unresolve_thread", (e, thread_id) =>
 				@showCommentByThreadId(thread_id)
-			
+
 			@$scope.$on "review-panel:recalculate-screen-positions", () =>
 				@recalculateReviewEntriesScreenPositions()
 
@@ -53,7 +53,7 @@ define [
 					@$scope.$evalAsync () =>
 						changingSelection = false
 						@updateFocus()
-			
+
 			onResize = () =>
 				@recalculateReviewEntriesScreenPositions()
 
@@ -99,7 +99,7 @@ define [
 					bindToAce()
 				else
 					unbindFromAce()
-		
+
 		disconnectFromDoc: (doc) ->
 			@changeIdToMarkerIdMap = {}
 			doc.off "ranges:clear"
@@ -111,18 +111,18 @@ define [
 				@$scope.sharejsDoc?.track_changes_as = window.user.id or "anonymous"
 			else
 				@$scope.sharejsDoc?.track_changes_as = null
-		
+
 		connectToDoc: (doc) ->
 			@rangesTracker = doc.ranges
 			@setTrackChanges(@$scope.trackChanges)
-			
+
 			doc.on "ranges:dirty", () =>
 				@updateAnnotations()
 			doc.on "ranges:clear", () =>
 				@clearAnnotations()
 			doc.on "ranges:redraw", () =>
 				@redrawAnnotations()
-		
+
 		clearAnnotations: () ->
 			session = @editor.getSession()
 			for change_id, markers of @changeIdToMarkerIdMap
@@ -139,9 +139,9 @@ define [
 
 			for comment in @rangesTracker.comments
 				@_onCommentAdded(comment)
-			
+
 			@broadcastChange()
-		
+
 		_doneUpdateThisLoop: false
 		_pendingUpdates: false
 		updateAnnotations: () ->
@@ -161,9 +161,9 @@ define [
 
 		_doUpdateAnnotations: () ->
 			dirty = @rangesTracker.getDirtyState()
-			
+
 			updateMarkers = false
-			
+
 			for id, change of dirty.change.added
 				if change.op.i?
 					@_onInsertAdded(change)
@@ -177,7 +177,7 @@ define [
 			for id, change of dirty.change.moved
 				updateMarkers = true
 				@_onChangeMoved(change)
-				
+
 			for id, comment of dirty.comment.added
 				@_onCommentAdded(comment)
 			for id, comment of dirty.comment.removed
@@ -185,7 +185,7 @@ define [
 			for id, comment of dirty.comment.moved
 				updateMarkers = true
 				@_onCommentMoved(comment)
-			
+
 			@rangesTracker.resetDirtyState()
 			if updateMarkers
 				@editor.renderer.updateBackMarkers()
@@ -195,18 +195,18 @@ define [
 			op = { c: content, p: offset, t: thread_id }
 			# @rangesTracker.applyOp op # Will apply via sharejs
 			@$scope.sharejsDoc.submitOp op
-		
+
 		addCommentToSelection: (thread_id, offset, length) ->
 			start = @_shareJsOffsetToAcePosition(offset)
 			end = @_shareJsOffsetToAcePosition(offset + length)
 			range = new Range(start.row, start.column, end.row, end.column)
 			content = @editor.session.getTextRange(range)
 			@addComment(offset, content, thread_id)
-		
+
 		selectLineIfNoSelection: () ->
 			if @editor.selection.isEmpty()
 				@editor.selection.selectLine()
-		
+
 		acceptChangeIds: (change_ids) ->
 			@rangesTracker.removeChangeIds(change_ids)
 			@updateAnnotations()
@@ -225,12 +225,12 @@ define [
 			#
 			#     foo quux baz
 			#         |--| -> insertion of "quux", op 1, at position 4
-			#             | -> deletion of "bar", op 2, pushed forward by "quux" to position 8 
+			#             | -> deletion of "bar", op 2, pushed forward by "quux" to position 8
 			#
-			# When rejecting these changes at once, if the insertion is rejected first, we get unexpected 
+			# When rejecting these changes at once, if the insertion is rejected first, we get unexpected
 			# results. What happens is:
 			#
-			#     1) Rejecting the insertion deletes the added word "quux", i.e., it removes 4 chars 
+			#     1) Rejecting the insertion deletes the added word "quux", i.e., it removes 4 chars
 			#        starting from position 4;
 			#
 			#           "foo quux baz" -> "foo  baz"
@@ -247,27 +247,27 @@ define [
 			#      "foo  bazbar" (note "bar" readded at position 8)
 			#
 			# The issue happens because of step 1. To revert the insertion of "quux", 4 characters are deleted
-			# from position 4. This includes the position where the deletion exists; when that position is 
+			# from position 4. This includes the position where the deletion exists; when that position is
 			# cleared, the RangesTracker considers that the deletion is gone and stops tracking/updating it.
 			# As we still hold a reference to it, the code tries to revert it by readding the deleted text, but
 			# does so at the outdated position (position 8, which was valid when "quux" was present).
 			#
-			# To avoid this kind of problem, we need to make sure that reverting operations doesn't affect 
-			# subsequent operations that come after. Reverse sorting the operations based on position will 
+			# To avoid this kind of problem, we need to make sure that reverting operations doesn't affect
+			# subsequent operations that come after. Reverse sorting the operations based on position will
 			# achieve it; in the case above, it makes sure that the the deletion is reverted first:
 			#
-			#     1) Rejecting the deletion adds the deleted word "bar" at position 8 
+			#     1) Rejecting the deletion adds the deleted word "bar" at position 8
 			#
 			#            "foo quux baz" -> "foo quuxbar baz"
-			#                                       | -> deletion of "bar" is reverted by 
+			#                                       | -> deletion of "bar" is reverted by
 			#                                            reinserting "bar" at position 8
 			#
-			#     2) Rejecting the insertion deletes the added word "quux", i.e., it removes 4 chars 
+			#     2) Rejecting the insertion deletes the added word "quux", i.e., it removes 4 chars
 			#        starting from position 4 and achieves the expected result:
 			#
 			#           "foo quuxbar baz" -> "foo bar baz"
 			#                |--| -> 4 characters to be removed
-			
+
 			changes.sort((a, b) -> b.op.p - a.op.p)
 
 			session = @editor.getSession()
@@ -303,7 +303,7 @@ define [
 				if resolve_ids[comment.op.t]
 					@_onCommentRemoved(comment)
 			@broadcastChange()
-			
+
 		showCommentByThreadId: (thread_id) ->
 			for comment in @rangesTracker?.comments or []
 				if comment.op.t == thread_id
@@ -339,7 +339,7 @@ define [
 				return if change.action != "insert"
 				pasted_text = change.lines.join("\n")
 				paste_offset = @_aceRangeToShareJs(change.start)
-				# We have to wait until the change has been processed by the range tracker, 
+				# We have to wait until the change has been processed by the range tracker,
 				# since if we move the ops into place beforehand, they will be moved again
 				# when the changes are processed by the range tracker. This ranges:dirty
 				# event is fired after the doc has applied the changes to the range tracker.
@@ -374,7 +374,7 @@ define [
 						end = start
 					expected_markers.push { marker_id: background_marker_id, start, end }
 					expected_markers.push { marker_id: callout_marker_id, start, end: start }
-			
+
 			for comment in @rangesTracker.comments
 				if @changeIdToMarkerIdMap[comment.id]?
 					{background_marker_id, callout_marker_id} = @changeIdToMarkerIdMap[comment.id]
@@ -382,7 +382,7 @@ define [
 					end = @_shareJsOffsetToAcePosition(comment.op.p + comment.op.c.length)
 					expected_markers.push { marker_id: background_marker_id, start, end }
 					expected_markers.push { marker_id: callout_marker_id, start, end: start }
-			
+
 			for {marker_id, start, end} in expected_markers
 				marker = markers[marker_id]
 				delete markers[marker_id]
@@ -391,11 +391,11 @@ define [
 						marker.range.end.row != end.row or
 						marker.range.end.column != end.column
 					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: () ->
 			selection = @editor.getSelectionRange()
 			selection_start = @_aceRangeToShareJs(selection.start)
@@ -403,10 +403,10 @@ define [
 			entries = @_getCurrentDocEntries()
 			is_selection = (selection_start != selection_end)
 			@$scope.$emit "editor:focus:changed", selection_start, selection_end, is_selection
-		
+
 		broadcastChange: () ->
 			@$scope.$emit "editor:track-changes:changed", @$scope.docId
-		
+
 		recalculateReviewEntriesScreenPositions: () ->
 			session = @editor.getSession()
 			renderer = @editor.renderer
@@ -455,7 +455,7 @@ define [
 					first_row > @end.row or last_row < @start.row
 				return @
 			return ace_range
-		
+
 		_createCalloutMarker: (position, klass) ->
 			session = @editor.getSession()
 			callout_range = @_makeZeroWidthRange(position)
@@ -486,21 +486,21 @@ define [
 
 			callout_marker_id = @_createCalloutMarker(position, "track-changes-deleted-marker-callout")
 			@changeIdToMarkerIdMap[change.id] = { background_marker_id, callout_marker_id }
-		
+
 		_onInsertRemoved: (change) ->
 			{background_marker_id, callout_marker_id} = @changeIdToMarkerIdMap[change.id]
 			delete @changeIdToMarkerIdMap[change.id]
 			session = @editor.getSession()
 			session.removeMarker background_marker_id
 			session.removeMarker callout_marker_id
-		
+
 		_onDeleteRemoved: (change) ->
 			{background_marker_id, callout_marker_id} = @changeIdToMarkerIdMap[change.id]
 			delete @changeIdToMarkerIdMap[change.id]
 			session = @editor.getSession()
 			session.removeMarker background_marker_id
 			session.removeMarker callout_marker_id
-		
+
 		_onCommentAdded: (comment) ->
 			if @rangesTracker.resolvedThreadIds[comment.op.t]
 				# Comment is resolved so shouldn't be displayed.
@@ -515,7 +515,7 @@ define [
 				background_marker_id = session.addMarker background_range, "track-changes-marker track-changes-comment-marker", "text"
 				callout_marker_id = @_createCalloutMarker(start, "track-changes-comment-marker-callout")
 				@changeIdToMarkerIdMap[comment.id] = { background_marker_id, callout_marker_id }
-		
+
 		_onCommentRemoved: (comment) ->
 			if @changeIdToMarkerIdMap[comment.id]?
 				# Resolved comments may not have marker ids
@@ -532,11 +532,11 @@ define [
 		_aceChangeToShareJs: (delta) ->
 			lines = @editor.getSession().getDocument().getLines 0, delta.start.row
 			return AceShareJsCodec.aceChangeToShareJs(delta, lines)
-		
+
 		_shareJsOffsetToAcePosition: (offset) ->
 			lines = @editor.getSession().getDocument().getAllLines()
 			return AceShareJsCodec.shareJsOffsetToAcePosition(offset, lines)
-		
+
 		_onChangeMoved: (change) ->
 			start = @_shareJsOffsetToAcePosition(change.op.p)
 			if change.op.i?
@@ -544,12 +544,12 @@ define [
 			else
 				end = start
 			@_updateMarker(change.id, start, end)
-		
+
 		_onCommentMoved: (comment) ->
 			start = @_shareJsOffsetToAcePosition(comment.op.p)
 			end = @_shareJsOffsetToAcePosition(comment.op.p + comment.op.c.length)
 			@_updateMarker(comment.id, start, end)
-	
+
 		_updateMarker: (change_id, start, end) ->
 			return if !@changeIdToMarkerIdMap[change_id]?
 			session = @editor.getSession()
@@ -563,4 +563,3 @@ define [
 				callout_marker = markers[callout_marker_id]
 				callout_marker.range.start = start
 				callout_marker.range.end = start
-

+ 1 - 1
services/web/public/coffee/ide/editor/sharejs/vendor/server/db/pg.coffee

@@ -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

+ 8 - 9
services/web/public/coffee/ide/editor/sharejs/vendor/server/model.coffee

@@ -177,7 +177,7 @@ module.exports = Model = (db, options) ->
         # The callback is called with the version of the document at which the op was applied.
         # This is the op.v after transformation, and its doc.v - 1.
         callback null, opData.v
-    
+
         # I need a decent strategy here for deciding whether or not to save the snapshot.
         #
         # The 'right' strategy looks something like "Store the snapshot whenever the snapshot
@@ -219,13 +219,13 @@ module.exports = Model = (db, options) ->
         dbMeta: dbMeta
 
       doc.opQueue = makeOpQueue docName, doc
-      
+
       refreshReapingTimeout docName
       model.emit 'add', docName, data
       callback null, doc for callback in callbacks if callbacks
 
     doc
-  
+
   # This is a little helper wrapper around db.getOps. It does two things:
   #
   # - If there's no database set, it returns an error to the callback
@@ -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'
@@ -400,7 +400,7 @@ module.exports = Model = (db, options) ->
 
   # Perminantly deletes the specified document.
   # If listeners are attached, they are removed.
-  # 
+  #
   # The callback is called with (error) if there was an error. If error is null / undefined, the
   # document was deleted.
   #
@@ -484,7 +484,7 @@ module.exports = Model = (db, options) ->
   # Apply an op to the specified document.
   # The callback is passed (error, applied version #)
   # opData = {op:op, v:v, meta:metadata}
-  # 
+  #
   # Ops are queued before being applied so that the following code applies op C before op B:
   # model.applyOp 'doc', OPA, -> model.applyOp 'doc', OPB
   # model.applyOp 'doc', OPC
@@ -501,7 +501,7 @@ module.exports = Model = (db, options) ->
   # TODO: op and meta should be combineable in the op that gets sent
   @applyMetaOp = (docName, metaOpData, callback) ->
     {path, value} = metaOpData.meta
-   
+
     return callback? "path should be an array" unless isArray path
 
     load docName, (error, doc) ->
@@ -522,7 +522,7 @@ module.exports = Model = (db, options) ->
   #
   # The callback is called once the listener is attached, but before any ops have been passed
   # to the listener.
-  # 
+  #
   # This will _not_ edit the document metadata.
   #
   # If there are any listeners, we don't purge the document from the cache. But be aware, this behaviour
@@ -600,4 +600,3 @@ module.exports = Model = (db, options) ->
 
 # Model inherits from EventEmitter.
 Model:: = new EventEmitter
-

+ 2 - 3
services/web/public/coffee/ide/pdf/controllers/PdfController.coffee

@@ -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
 

+ 6 - 6
services/web/public/coffee/ide/pdfng/directives/pdfViewer.coffee

@@ -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
@@ -307,7 +307,7 @@ define [
 					return unless scale?
 					origposition = angular.copy scope.position
 					# console.log 'origposition', origposition
-					
+
 					if not spinnerTimer?
 						spinnerTimer = setTimeout () ->
 							spinner.add(element)
@@ -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
@@ -408,12 +408,12 @@ define [
 						element.scrollTop(currentScrollTop + delta)
 
 				element.on 'mousedown', (e) ->
-					# We're checking that the event target isn't the directive root element 
+					# We're checking that the event target isn't the directive root element
 					# to make sure that the click was within a PDF page - no point in showing
 					# the text layer when the click is outside.
 					# If the user clicks a PDF page, the mousedown target will be the canvas
 					# element (or the text layer one). Alternatively, if the event target is
-					# the root element, we can assume that the user has clicked either the 
+					# the root element, we can assume that the user has clicked either the
 					# grey background area or the scrollbars.
 					if e.target != element[0] and !_hasSelection()
 						element.addClass 'pdfjs-viewer-show-text'
@@ -444,7 +444,7 @@ define [
 				_hasSelection = () ->
 					selection = window.getSelection?()
 					# check the selection collapsed state in preference to
-					# using selection.toString() as the latter is "" when 
+					# using selection.toString() as the latter is "" when
 					# the selection is hidden (e.g. while viewing logs)
 					return selection? and _isSelectionWithinPDF(selection) and !selection.isCollapsed
 

+ 5 - 5
services/web/public/coffee/main/learn.coffee

@@ -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 =
@@ -38,7 +38,7 @@ define [
 				url :"/learn/#{page_underscored}##{section_underscored}"
 				content: content
 			return result
-			
+
 		updateHits = (hits)->
 			$scope.safeApply ->
 				$scope.hits = hits
@@ -48,7 +48,7 @@ define [
 			if !query? or query.length == 0
 				updateHits []
 				return
-				
+
 			algoliaSearch.searchWiki query, (err, response)->
 				if response.hits.length == 0
 					updateHits []
@@ -56,4 +56,4 @@ define [
 					hits = _.map response.hits, buildHitViewModel
 					updateHits hits
 
-	App.controller "LearnController", () -> 
+	App.controller "LearnController", () ->

+ 3 - 3
services/web/public/coffee/main/templates.coffee

@@ -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 =
@@ -53,4 +53,4 @@ define [
 					updateHits []
 				else
 					hits = _.map response.hits, buildHitViewModel
-					updateHits hits
+					updateHits hits