mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Trim project name and validate whitespace (#14976)
* add whitespace check to fixProjectname * add whitespace check to validateProjectName * Log a warning if the project name starts or ends with whitespace --------- Co-authored-by: Alf Eaton <alf.eaton@overleaf.com> GitOrigin-RevId: ba81e0f795e52dbba92c9fbb48cebfd8e547af08
This commit is contained in:
parent
6b8dfaa782
commit
ee4e1f5429
1 changed files with 17 additions and 1 deletions
|
@ -137,6 +137,19 @@ async function validateProjectName(name) {
|
|||
'Project name cannot contain \\ characters'
|
||||
)
|
||||
}
|
||||
if (name !== name.trim()) {
|
||||
const message = 'Project name cannot start or end with whitespace'
|
||||
|
||||
const error = new Errors.InvalidNameError({
|
||||
message,
|
||||
info: { name },
|
||||
})
|
||||
|
||||
logger.warn({ error }, message)
|
||||
|
||||
// TODO: throw the error, after checking that it won't cause problems
|
||||
// throw error
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: we should put a lock around this to make it completely safe, but we would need to do that at
|
||||
|
@ -163,7 +176,10 @@ async function generateUniqueName(userId, name, suffixes = []) {
|
|||
}
|
||||
|
||||
function fixProjectName(name) {
|
||||
if (name === '' || !name) {
|
||||
// Remove any leading or trailing whitespace
|
||||
name = typeof name === 'string' ? name.trim() : ''
|
||||
// Apply a default name if the name is empty
|
||||
if (name === '') {
|
||||
name = 'Untitled'
|
||||
}
|
||||
if (name.indexOf('/') > -1) {
|
||||
|
|
Loading…
Reference in a new issue