mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-02 09:25:47 +00:00
strip quotes from mainFile
This commit is contained in:
parent
418bc10a18
commit
0d4143205d
2 changed files with 24 additions and 1 deletions
|
@ -35,11 +35,15 @@ module.exports = ProjectRootDocManager =
|
|||
setRootDocFromName: (project_id, rootDocName, callback = (error) ->) ->
|
||||
ProjectEntityHandler.getAllDocPathsFromProjectById project_id, (error, docPaths) ->
|
||||
return callback(error) if error?
|
||||
# strip off leading and trailing quotes from rootDocName
|
||||
rootDocName = rootDocName.replace(/^\'|\'$/g,"")
|
||||
# prepend a slash for the root folder if not present
|
||||
rootDocName = "/#{rootDocName}" if rootDocName[0] isnt '/'
|
||||
# find the root doc from the filename
|
||||
root_doc_id = null
|
||||
for doc_id, path of docPaths
|
||||
# docpaths have a leading / so allow matching "folder/filename" and "/folder/filename"
|
||||
if path == rootDocName or path == "/#{rootDocName}"
|
||||
if path == rootDocName
|
||||
root_doc_id = doc_id
|
||||
# try a basename match if there was no match
|
||||
if !root_doc_id
|
||||
|
|
|
@ -133,6 +133,25 @@ describe 'ProjectRootDocManager', ->
|
|||
@ProjectEntityUpdateHandler.setRootDoc.calledWith(@project_id, "doc-id-3")
|
||||
.should.equal true
|
||||
|
||||
describe "when there is a suitable root doc but the filename is in quotes", ->
|
||||
beforeEach (done)->
|
||||
@docPaths =
|
||||
"doc-id-1": "/chapter1.tex"
|
||||
"doc-id-2": "/main.tex"
|
||||
"doc-id-3": "/nested/chapter1a.tex"
|
||||
"doc-id-4": "/nested/chapter1b.tex"
|
||||
@ProjectEntityHandler.getAllDocPathsFromProjectById = sinon.stub().callsArgWith(1, null, @docPaths)
|
||||
@ProjectEntityUpdateHandler.setRootDoc = sinon.stub().callsArgWith(2)
|
||||
@ProjectRootDocManager.setRootDocFromName @project_id, "'main.tex'", done
|
||||
|
||||
it "should check the docs of the project", ->
|
||||
@ProjectEntityHandler.getAllDocPathsFromProjectById.calledWith(@project_id)
|
||||
.should.equal true
|
||||
|
||||
it "should set the root doc to main.tex", ->
|
||||
@ProjectEntityUpdateHandler.setRootDoc.calledWith(@project_id, "doc-id-2")
|
||||
.should.equal true
|
||||
|
||||
describe "when there is no suitable root doc", ->
|
||||
beforeEach (done)->
|
||||
@docPaths =
|
||||
|
|
Loading…
Reference in a new issue