Skip to content

Conversation

@nikithauc
Copy link
Contributor

URL parsing failed because the parsePath() function did not considering nested query functions. Changed the function to split the query parameters on the first equals sign( OData Parsing rules).

Also, added comments to few query option functions mentioning their expected behaviour.

…equals sign considering nested queries. Added comments to query functions
@ghost
Copy link

ghost commented Jul 28, 2020

CLA assistant check
All CLA requirements met.

Co-authored-by: Mustafa Zengin <muzengin@microsoft.com>
@jobala
Copy link

jobala commented Aug 3, 2020

These changes work for me, except for the edge case pointed by @zengin.

I have a few suggestions regarding improving the code's readability.

  1. We can improve readability of the if block by using variable names instead of expressions.
const hasOdataQueryName = oDataQueryNames.indexOf(paramKey) !== -1; if (hasOdataQueryName) { ... } 
  1. By extracting smaller functions from query() ie handleQueryString() & handleQueryDictionary we make it easy to see what the function is doing.

What do you think of extracting the changes added to query() in a separate function then call the extracted function in parsePath() and query()?

if (queryDictionaryOrString.hasOwnProperty(key)) {
otherURLQueryParams[key] = queryDictionaryOrString[key];
paramKey = key;
paramValue = queryDictionaryOrString[key];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't there be a break here? if not can you add a comment about the intent of the code here. once paramKey is set it's not clear why continue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a mistake on my part. Corrected the code so that the iteration records key and value for each parameter in the dictionary.

* @public
* Appends query string to the urlComponent
* @param {string|KeyValuePairObjectStringNumber} queryDictionaryOrString - The query value
* @returns The same GraphRequest instance that is being called with
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you comment here on what the modification the graphrequest is. It currently reads like I passed in something and got the same thing back.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more information in some comments. There are more comments like this one. Will change them in another PR.

@nikithauc
Copy link
Contributor Author

These changes work for me, except for the edge case pointed by @zengin.

I have a few suggestions regarding improving the code's readability.

  1. We can improve readability of the if block by using variable names instead of expressions.
const hasOdataQueryName = oDataQueryNames.indexOf(paramKey) !== -1; if (hasOdataQueryName) { ... } 
  1. By extracting smaller functions from query() ie handleQueryString() & handleQueryDictionary we make it easy to see what the function is doing.

What do you think of extracting the changes added to query() in a separate function then call the extracted function in parsePath() and query()?

I have added a private function which is called by parsePath() and query() function. I have tried using variables in place of expressions wherever the expression appears more than once. And tried breaking down to small functions.

Copy link
Contributor

@zengin zengin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a test centric approach for this fix.

@MIchaelMainer MIchaelMainer merged commit ed902ec into dev Aug 7, 2020
@nikithauc nikithauc deleted the JS_Issue_291_URLParsingCorrection branch August 7, 2020 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

6 participants