diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2019-04-03 15:57:16 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-03 15:57:16 +0300 |
commit | 428ebd85b159a4059020df872d1823cf0ba75584 (patch) | |
tree | 168309deaaa6947a3c0284fa92409a1b195aa4de /src | |
parent | cde48a3878156adfabcf61e15787c8a461380dc3 (diff) | |
parent | e93edbc24ce1db4a4eda7aecd4474ad09dc40dd1 (diff) |
Merge pull request #1643 from nextcloud/fix/uid-parser-default-accountv0.12.0-RC3
Fix/uid parser default account
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/unit/util/EnvelopeUidParser.spec.js | 44 | ||||
-rw-r--r-- | src/util/EnvelopeUidParser.js | 2 |
2 files changed, 45 insertions, 1 deletions
diff --git a/src/tests/unit/util/EnvelopeUidParser.spec.js b/src/tests/unit/util/EnvelopeUidParser.spec.js new file mode 100644 index 000000000..42730fda0 --- /dev/null +++ b/src/tests/unit/util/EnvelopeUidParser.spec.js @@ -0,0 +1,44 @@ +/* + * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +import {parseUid} from '../../../util/EnvelopeUidParser' + +describe('EnvelopeUidParser', () => { + it ('parses a simple UID', () => { + const uid = '1-SU5CT1g=-123' + + const parsed = parseUid(uid) + + expect(parsed.accountId).to.equal(1) + expect(parsed.folderId).to.equal('SU5CT1g=') + expect(parsed.id).to.equal(123) + }) + + it ('parses the default account UID', () => { + const uid = '-2-SU5CT1g=-123' + + const parsed = parseUid(uid) + + expect(parsed.accountId).to.equal(-2) + expect(parsed.folderId).to.equal('SU5CT1g=') + expect(parsed.id).to.equal(123) + }) +}) diff --git a/src/util/EnvelopeUidParser.js b/src/util/EnvelopeUidParser.js index ecc9d92a9..4aabdcf0f 100644 --- a/src/util/EnvelopeUidParser.js +++ b/src/util/EnvelopeUidParser.js @@ -19,7 +19,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -const reg = /^(\d+)-((?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4}))-(\d+)$/ +const reg = /^(-?\d+)-((?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4}))-(\d+)$/ export const parseUid = str => { const match = reg.exec(str) |