Skip to content

Commit 11c6905

Browse files
committed
Validate new style IDs before returning data in api.new.get-functions
1 parent 3d77868 commit 11c6905

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/gmail.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3587,6 +3587,9 @@ var Gmail = function(localJQuery) {
35873587
* @param email_id: new style email id. Legacy IDs not supported. If empty, default to latest in view.
35883588
*/
35893589
api.new.get.email_data = function(email_id) {
3590+
if (!email_id.statsWith("msg")) {
3591+
throw new Error("Legacy email-ID used in new API!");
3592+
}
35903593
email_id = email_id || api.new.get.email_id();
35913594
return api.cache.emailIdCache[email_id];
35923595
};
@@ -3597,6 +3600,10 @@ var Gmail = function(localJQuery) {
35973600
* @param thread_id: new style thread id. Legacy IDs not supported. If empty, default to current.
35983601
*/
35993602
api.new.get.thread_data = function(thread_id) {
3603+
if (!thread_id.statsWith("thread")) {
3604+
throw new Error("Legacy email-ID used where new-type thread-id expected!");
3605+
}
3606+
36003607
thread_id = thread_id || api.new.get.thread_id();
36013608
return api.cache.threadCache[thread_id];
36023609
};

test/test.new.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use strict";
2+
let assert = require('assert');
3+
let Gmail = require('../src/gmail').Gmail;
4+
let gmail = new Gmail();
5+
6+
describe("gmail.new.get", () => {
7+
it("email_data() rejects legacy-style IDs", () => {
8+
let failed = false;
9+
try {
10+
let res = gmail.new.get.email_data("16a0d1f820d515e2");
11+
} catch (err) {
12+
failed = true;
13+
}
14+
15+
assert.equal(true, failed);
16+
});
17+
18+
it("thread_data() rejects legacy-style IDs", () => {
19+
let failed = false;
20+
try {
21+
let res = gmail.new.get.thread_data("16a0d1f820d515e2");
22+
} catch (err) {
23+
failed = true;
24+
}
25+
26+
assert.equal(true, failed);
27+
});
28+
});

0 commit comments

Comments
 (0)