Merge pull request #856 from sharelatex/ns-use-regex-test

Use regex test instead of string match
This commit is contained in:
Shane Kilkelly 2018-08-29 09:21:40 +01:00 committed by GitHub
commit 6ee2a83885
20 changed files with 117 additions and 122 deletions

View file

@ -217,8 +217,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

@ -466,6 +466,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

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

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

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

View file

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

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

@ -163,12 +163,11 @@ define [
end = change.end
{lineUpToCursor, commandFragment} = Helpers.getContext(@editor, end)
if ((i = lineUpToCursor.indexOf('%')) > -1 and lineUpToCursor[i-1] != '\\')
console.log lineUpToCursor, i
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
@ -185,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 () =>
@ -209,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

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

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

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

View file

@ -356,7 +356,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
@ -489,8 +489,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
@ -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

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 =
@ -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", () ->

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