Skip to content

Commit 56b46b6

Browse files
committed
Merge remote-tracking branch 'upstream/alpha' into alpha
2 parents cfc525d + 841ca1f commit 56b46b6

File tree

7 files changed

+45
-11
lines changed

7 files changed

+45
-11
lines changed

changelogs/CHANGELOG_alpha.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## [3.4.3-alpha.2](https://github.com/parse-community/Parse-SDK-JS/compare/3.4.3-alpha.1...3.4.3-alpha.2) (2022-05-29)
2+
3+
4+
### Bug Fixes
5+
6+
* invalid name for `Parse.Role` throws incorrect error ([#1481](https://github.com/parse-community/Parse-SDK-JS/issues/1481)) ([8326a6f](https://github.com/parse-community/Parse-SDK-JS/commit/8326a6f1d7cda0ca8c6f1a3a7ea82448881e118e))
7+
18
## [3.4.3-alpha.1](https://github.com/parse-community/Parse-SDK-JS/compare/3.4.2...3.4.3-alpha.1) (2022-05-02)
29

310

integration/test/ParseACLTest.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,13 @@ describe('Parse.ACL', () => {
533533
const obj1withInclude = await query.first();
534534
assert(obj1withInclude.get('other').get('ACL'));
535535
});
536+
537+
it('prevents save with invalid role name', async () => {
538+
expect(() => new Parse.Role(':%#', new Parse.ACL())).toThrow(
539+
new Parse.Error(
540+
Parse.Error.OTHER_CAUSE,
541+
`A role's name can be only contain alphanumeric characters, _, -, and spaces.`
542+
)
543+
);
544+
});
536545
});

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "parse",
3-
"version": "3.4.3-alpha.1",
3+
"version": "3.4.3-alpha.2",
44
"description": "The Parse JavaScript SDK",
55
"homepage": "https://parseplatform.org/",
66
"keywords": [

src/ParseRole.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class ParseRole extends ParseObject {
7575
* @returns {(ParseObject|boolean)} true if the set succeeded.
7676
*/
7777
setName(name: string, options?: mixed): ParseObject | boolean {
78+
this._validateName(name);
7879
return this.set('name', name, options);
7980
}
8081

@@ -108,6 +109,18 @@ class ParseRole extends ParseObject {
108109
return this.relation('roles');
109110
}
110111

112+
_validateName(newName) {
113+
if (typeof newName !== 'string') {
114+
throw new ParseError(ParseError.OTHER_CAUSE, "A role's name must be a String.");
115+
}
116+
if (!/^[0-9a-zA-Z\-_ ]+$/.test(newName)) {
117+
throw new ParseError(
118+
ParseError.OTHER_CAUSE,
119+
"A role's name can be only contain alphanumeric characters, _, " + '-, and spaces.'
120+
);
121+
}
122+
}
123+
111124
validate(attrs: AttributeMap, options?: mixed): ParseError | boolean {
112125
const isInvalid = super.validate(attrs, options);
113126
if (isInvalid) {
@@ -125,14 +138,10 @@ class ParseRole extends ParseObject {
125138
"A role's name can only be set before it has been saved."
126139
);
127140
}
128-
if (typeof newName !== 'string') {
129-
return new ParseError(ParseError.OTHER_CAUSE, "A role's name must be a String.");
130-
}
131-
if (!/^[0-9a-zA-Z\-_ ]+$/.test(newName)) {
132-
return new ParseError(
133-
ParseError.OTHER_CAUSE,
134-
"A role's name can be only contain alphanumeric characters, _, " + '-, and spaces.'
135-
);
141+
try {
142+
this._validateName(newName);
143+
} catch (e) {
144+
return e;
136145
}
137146
}
138147
return false;

src/ParseUser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ class ParseUser extends ParseObject {
779779
* Request an email verification.
780780
*
781781
* @param {string} email The email address associated with the user that
782-
* forgot their password.
782+
* needs to verify their email.
783783
* @param {object} options
784784
* @static
785785
* @returns {Promise}

src/__tests__/ParseRole-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ describe('ParseRole', () => {
4545
expect(role.getName()).toBe('');
4646
});
4747

48+
it('should throw error string with invalid name', () => {
49+
expect(() => new ParseRole('invalid:name', new ParseACL())).toThrow(
50+
new ParseError(
51+
ParseError.OTHER_CAUSE,
52+
"A role's name can be only contain alphanumeric characters, _, " + '-, and spaces.'
53+
)
54+
);
55+
});
56+
4857
it('can validate attributes', () => {
4958
const acl = new ParseACL({ aUserId: { read: true, write: true } });
5059
const role = new ParseRole('admin', acl);

0 commit comments

Comments
 (0)