Autodesk-Forge / learn.forge.viewmodels

Learn Forge Tutorial: View your models using 2-legged OAuth. Available in Nodejs, .NET, Go, PHP & Java
http://learnforge.autodesk.io
MIT License
105 stars 86 forks source link

Add bucketKey sanitization #46

Closed deepalics0044 closed 3 years ago

petrbroz commented 3 years ago

I'm not sure if that code is correct. It sounds like it actually throws an alert when the bucket name is valid.

Shouldn't it be something like this instead?

const regex = /^[\-_.a-z0-9]{3,128}$/g;
if (!bucketKey.match(regex)) {
    alert('Invalid bucket name!');
    return;
}
petrbroz commented 3 years ago

Closing in favor of PR #53.

deepalics0044 commented 3 years ago

pattern [^-_.a-z0-9] match characters that are not listed in the range .

So condition should be if (reg.test(bucketKey))

var reg = new RegExp(/[^-_.a-z0-9]/g);

if (reg.test(bucketKey)) { alert('Wrong Bucketkey format!'); return; }

petrbroz commented 3 years ago

Hi Deepali, I'm not sure I understand. Is the new code broken?

The regular expression I'm using is /^[\-_.a-z0-9]{3,128}$/g. The ^ symbol is before the [] group, not inside, and it's meant to represent the "beginning of string".