Skip to content

Commit 008a581

Browse files
authored
Merge pull request #1462 from microsoftgraph/feature/missing-commits
set url to stripped path
2 parents 846e747 + 0822caf commit 008a581

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/content/BatchRequestContent.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,8 @@ export class BatchRequestContent {
198198
const requestData: RequestData = {
199199
url: "",
200200
};
201-
const hasHttpRegex = new RegExp("^https?://");
202201
// Stripping off hostname, port and url scheme
203-
requestData.url = hasHttpRegex.test(request.url) ? "/" + request.url.split(/.*?\/\/.*?\//)[1] : request.url;
202+
requestData.url = request.url.replace(/^(?:http)?s?:?(?:\/\/)?[^/]+\/(?:v1.0|beta)?/i, ""); // replaces <scheme>?<?>?<//><hostname:port>+</>?<version>+ by an empty string
204203
requestData.method = request.method;
205204
const headers = {};
206205
request.headers.forEach((value, key) => {

test/common/content/BatchRequestContent.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ const folderDetails = {
1717
name: folderName,
1818
folder: {},
1919
};
20+
const driveRootChildrenPath = "/me/drive/root/children";
2021

21-
const createFolderRequest = new Request(DUMMY_BASE_URL + "/me/drive/root/children", {
22+
const createFolderRequest = new Request(DUMMY_BASE_URL + driveRootChildrenPath, {
2223
method: "POST",
2324
headers: {
2425
"Content-type": "application/json",
@@ -213,6 +214,14 @@ describe("BatchRequestContent.ts", () => {
213214
assert.isDefined(content.requests[0].body);
214215
assert.equal(typeof content.requests[0].body, "object");
215216
});
217+
218+
it("Should parse path with url", async () => {
219+
const req = getCreateFolderRequestCopy();
220+
req.request = new Request("https://graph.microsoft.com/v1.0" + driveRootChildrenPath);
221+
const batchReq = new BatchRequestContent([req]);
222+
const content = await batchReq.getContent();
223+
assert.equal(content.requests[0].url, "/me/drive/root/children");
224+
});
216225
});
217226

218227
describe("removeDependency", function() {

0 commit comments

Comments
 (0)