Skip to content

Commit f83adf9

Browse files
fix #27, other fixes, additional tests
1 parent dde5981 commit f83adf9

File tree

9 files changed

+75
-8
lines changed

9 files changed

+75
-8
lines changed

dist/dynamics-web-api-callbacks.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,18 @@ function convertRequestOptions(request, functionName, url, joinSymbol, config) {
428428
if (request.filter) {
429429
ErrorHelper.stringParameterCheck(request.filter, 'DynamicsWebApi.' + functionName, "request.filter");
430430
var removeBracketsFromGuidReg = /[^"']{([\w\d]{8}[-]?(?:[\w\d]{4}[-]?){3}[\w\d]{12})}(?:[^"']|$)/g;
431-
var filterResult = request.filter.replace(removeBracketsFromGuidReg, ' $1 ').trim();
431+
var filterResult = request.filter;
432+
433+
//fix bug 2018-06-11
434+
while ((m = removeBracketsFromGuidReg.exec(filterResult)) !== null) {
435+
if (m.index === removeBracketsFromGuidReg.lastIndex) {
436+
regex.lastIndex++;
437+
}
438+
439+
var replacement = m[0].endsWith(')') ? ')' : ' ';
440+
filterResult = filterResult.replace(m[0], ' ' + m[1] + replacement);
441+
}
442+
432443
requestArray.push("$filter=" + encodeURIComponent(filterResult));
433444
}
434445

@@ -857,7 +868,9 @@ function sendRequest(method, path, config, data, additionalHeaders, successCallb
857868

858869
for (var key in additionalHeaders) {
859870
batchBody.push(key + ': ' + additionalHeaders[key]);
860-
delete additionalHeaders[key];
871+
872+
//authorization header is an exception. bug #27
873+
if (key != 'Authorization') delete additionalHeaders[key];
861874
}
862875

863876
batchBody.push('\n--' + batchBoundary + '--');
@@ -1027,6 +1040,8 @@ if (!String.prototype.endsWith || !String.prototype.startsWith) {
10271040
* @property {Object} entity - A JavaScript object with properties corresponding to the logical name of entity attributes (exceptions are lookups and single-valued navigation properties).
10281041
* @property {string} impersonate - Impersonates the user. A String representing the GUID value for the Dynamics 365 system user id.
10291042
* @property {string} navigationProperty - A String representing the name of a single-valued navigation property. Useful when needed to retrieve information about a related record in a single request.
1043+
* @property {string} navigationPropertyKey - v.1.4.3+ A String representing navigation property's Primary Key (GUID) or Alternate Key(s). (For example, to retrieve Attribute Metadata).
1044+
* @property {string} metadataAttributeType - v.1.4.3+ Casts the AttributeMetadata to a specific type. (Used in requests to Attribute Metadata).
10301045
* @property {boolean} noCache - If set to 'true', DynamicsWebApi adds a request header 'Cache-Control: no-cache'. Default value is 'false'.
10311046
* @property {string} savedQuery - A String representing the GUID value of the saved query.
10321047
* @property {string} userQuery - A String representing the GUID value of the user query.

dist/dynamics-web-api-callbacks.min.js

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

dist/dynamics-web-api.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,9 @@ function sendRequest(method, path, config, data, additionalHeaders, successCallb
596596

597597
for (var key in additionalHeaders) {
598598
batchBody.push(key + ': ' + additionalHeaders[key]);
599-
delete additionalHeaders[key];
599+
600+
//authorization header is an exception. bug #27
601+
if (key != 'Authorization') delete additionalHeaders[key];
600602
}
601603

602604
batchBody.push('\n--' + batchBoundary + '--');
@@ -765,6 +767,8 @@ if (!String.prototype.endsWith || !String.prototype.startsWith) {
765767
* @property {Object} entity - A JavaScript object with properties corresponding to the logical name of entity attributes (exceptions are lookups and single-valued navigation properties).
766768
* @property {string} impersonate - Impersonates the user. A String representing the GUID value for the Dynamics 365 system user id.
767769
* @property {string} navigationProperty - A String representing the name of a single-valued navigation property. Useful when needed to retrieve information about a related record in a single request.
770+
* @property {string} navigationPropertyKey - v.1.4.3+ A String representing navigation property's Primary Key (GUID) or Alternate Key(s). (For example, to retrieve Attribute Metadata).
771+
* @property {string} metadataAttributeType - v.1.4.3+ Casts the AttributeMetadata to a specific type. (Used in requests to Attribute Metadata).
768772
* @property {boolean} noCache - If set to 'true', DynamicsWebApi adds a request header 'Cache-Control: no-cache'. Default value is 'false'.
769773
* @property {string} savedQuery - A String representing the GUID value of the saved query.
770774
* @property {string} userQuery - A String representing the GUID value of the user query.
@@ -2266,7 +2270,18 @@ function convertRequestOptions(request, functionName, url, joinSymbol, config) {
22662270
if (request.filter) {
22672271
ErrorHelper.stringParameterCheck(request.filter, 'DynamicsWebApi.' + functionName, "request.filter");
22682272
var removeBracketsFromGuidReg = /[^"']{([\w\d]{8}[-]?(?:[\w\d]{4}[-]?){3}[\w\d]{12})}(?:[^"']|$)/g;
2269-
var filterResult = request.filter.replace(removeBracketsFromGuidReg, ' $1 ').trim();
2273+
var filterResult = request.filter;
2274+
2275+
//fix bug 2018-06-11
2276+
while ((m = removeBracketsFromGuidReg.exec(filterResult)) !== null) {
2277+
if (m.index === removeBracketsFromGuidReg.lastIndex) {
2278+
regex.lastIndex++;
2279+
}
2280+
2281+
var replacement = m[0].endsWith(')') ? ')' : ' ';
2282+
filterResult = filterResult.replace(m[0], ' ' + m[1] + replacement);
2283+
}
2284+
22702285
requestArray.push("$filter=" + encodeURIComponent(filterResult));
22712286
}
22722287

dist/dynamics-web-api.min.js

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

lib/dynamics-web-api-callbacks.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ var dwaRequest = function () {
7878
* @property {Object} entity - A JavaScript object with properties corresponding to the logical name of entity attributes (exceptions are lookups and single-valued navigation properties).
7979
* @property {string} impersonate - Impersonates the user. A String representing the GUID value for the Dynamics 365 system user id.
8080
* @property {string} navigationProperty - A String representing the name of a single-valued navigation property. Useful when needed to retrieve information about a related record in a single request.
81+
* @property {string} navigationPropertyKey - v.1.4.3+ A String representing navigation property's Primary Key (GUID) or Alternate Key(s). (For example, to retrieve Attribute Metadata).
82+
* @property {string} metadataAttributeType - v.1.4.3+ Casts the AttributeMetadata to a specific type. (Used in requests to Attribute Metadata).
8183
* @property {boolean} noCache - If set to 'true', DynamicsWebApi adds a request header 'Cache-Control: no-cache'. Default value is 'false'.
8284
* @property {string} savedQuery - A String representing the GUID value of the saved query.
8385
* @property {string} userQuery - A String representing the GUID value of the user query.

lib/dynamics-web-api.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ var dwaRequest = function () {
7979
* @property {Object} entity - A JavaScript object with properties corresponding to the logical name of entity attributes (exceptions are lookups and single-valued navigation properties).
8080
* @property {string} impersonate - Impersonates the user. A String representing the GUID value for the Dynamics 365 system user id.
8181
* @property {string} navigationProperty - A String representing the name of a single-valued navigation property. Useful when needed to retrieve information about a related record in a single request.
82+
* @property {string} navigationPropertyKey - v.1.4.3+ A String representing navigation property's Primary Key (GUID) or Alternate Key(s). (For example, to retrieve Attribute Metadata).
83+
* @property {string} metadataAttributeType - v.1.4.3+ Casts the AttributeMetadata to a specific type. (Used in requests to Attribute Metadata).
8284
* @property {boolean} noCache - If set to 'true', DynamicsWebApi adds a request header 'Cache-Control: no-cache'. Default value is 'false'.
8385
* @property {string} savedQuery - A String representing the GUID value of the saved query.
8486
* @property {string} userQuery - A String representing the GUID value of the user query.

lib/requests/sendRequest.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ function sendRequest(method, path, config, data, additionalHeaders, successCallb
129129

130130
for (var key in additionalHeaders) {
131131
batchBody.push(key + ': ' + additionalHeaders[key]);
132-
delete additionalHeaders[key];
132+
133+
//authorization header is an exception. bug #27
134+
if (key != 'Authorization') delete additionalHeaders[key];
133135
}
134136

135137
batchBody.push('\n--' + batchBoundary + '--');

lib/utilities/RequestConverter.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,18 @@ function convertRequestOptions(request, functionName, url, joinSymbol, config) {
7575
if (request.filter) {
7676
ErrorHelper.stringParameterCheck(request.filter, 'DynamicsWebApi.' + functionName, "request.filter");
7777
var removeBracketsFromGuidReg = /[^"']{([\w\d]{8}[-]?(?:[\w\d]{4}[-]?){3}[\w\d]{12})}(?:[^"']|$)/g;
78-
var filterResult = request.filter.replace(removeBracketsFromGuidReg, ' $1 ').trim();
78+
var filterResult = request.filter;
79+
80+
//fix bug 2018-06-11
81+
while ((m = removeBracketsFromGuidReg.exec(filterResult)) !== null) {
82+
if (m.index === removeBracketsFromGuidReg.lastIndex) {
83+
regex.lastIndex++;
84+
}
85+
86+
var replacement = m[0].endsWith(')') ? ')' : ' ';
87+
filterResult = filterResult.replace(m[0], ' ' + m[1] + replacement);
88+
}
89+
7990
requestArray.push("$filter=" + encodeURIComponent(filterResult));
8091
}
8192

tests/common-tests.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,26 @@ describe("RequestConverter.convertRequestOptions -", function () {
412412
expect(result).to.deep.equal({ url: stubUrl, query: "$filter=" + encodeURIComponent("name eq 'name' and testid1 eq 0000a000-0000-0000-0000-000000000001 and testid2 eq 0000a000-0000-0000-0000-000000000002 and teststring eq '{0000a000-0000-0000-0000-000000000003}'"), headers: {} });
413413
});
414414

415+
//test bug 2018-06-11
416+
it("filter - grouping & remove brackets from guid ", function () {
417+
var dwaRequest = {
418+
filter: "name eq 'name' and (testid1 eq {0000a000-0000-0000-0000-000000000001} or testid2 eq {0000a000-0000-0000-0000-000000000002})"
419+
};
420+
421+
var result = RequestConverter.convertRequestOptions(dwaRequest, "", stubUrl);
422+
expect(result).to.deep.equal({ url: stubUrl, query: "$filter=" + encodeURIComponent("name eq 'name' and (testid1 eq 0000a000-0000-0000-0000-000000000001 or testid2 eq 0000a000-0000-0000-0000-000000000002)"), headers: {} });
423+
});
424+
425+
//test bug 2018-06-11
426+
it("filter - grouping & remove brackets from a single guid", function () {
427+
var dwaRequest = {
428+
filter: "name eq 'name' and (testid1 eq {0000a000-0000-0000-0000-000000000001})"
429+
};
430+
431+
var result = RequestConverter.convertRequestOptions(dwaRequest, "", stubUrl);
432+
expect(result).to.deep.equal({ url: stubUrl, query: "$filter=" + encodeURIComponent("name eq 'name' and (testid1 eq 0000a000-0000-0000-0000-000000000001)"), headers: {} });
433+
});
434+
415435
it("ifmatch empty", function () {
416436
var dwaRequest = {
417437
ifmatch: ""

0 commit comments

Comments
 (0)