ms-rest-js icon indicating copy to clipboard operation
ms-rest-js copied to clipboard

URLQuery.parse fails parsing when = sign in parameter value

Open kkaminski-github opened this issue 5 years ago • 10 comments

Hi!

I believe I have found a problem with parsing query part of URL In latest release available on github: https://github.com/Azure/ms-rest-js/blob/abc4f8f58ef1ac999315877eaf740c2bd0eddcbe/lib/url.ts#L71

Short context: I am trying to receive second page of my scale set virtual machines using following command:

computeClient.virtualMachineScaleSetVMs.listNext(`https://management.azure.com:443/subscriptions/1111111-1111-1111-1111-1111111111/resourceGroups/ae-workers/providers/Microsoft.Compute/virtualMachineScaleSets/ae-workers-scale-1000/virtualMachines?api-version=2020-06-01&$skiptoken=ODIzZnNkdi01YXNjLTEzc2EtMTI1NS1jYTNhc2QxMmRhMyEvU3Vic2NyaXB0aW9ucy8xMTExMTEtMTExMS0xMTExLTExMTEtMTExMTExMTExL1Jlc291cmNlR3JvdXBzL0FFLVdPUktFUlMvVk1TY2FsZVNldHMvQUUtV09SS0VSUy1TQ0FMRS0xMDAwL1ZNcy8xNDMz==`);

Parameter is the nextLink, which I received from previous execution of list method.

As you can see returned skiptoken is base64 encoded data with '==' signs at the end. When executing computeClient.virtualMachineScaleSetVMs.listNext URLQuery.parse is executed as well.

We can find there something:

case "ParameterValue":
                        switch (currentCharacter) {
                            case "=":
                                parameterName = "";
                                parameterValue = "";
                                currentState = "Invalid";
                                break;

I believe that this part should be removed - query param value can contain '=' sign. Please tell me if I'm wrong. My $skiptoken is not correctly parsed and in result I cannot get second page for my scale set virtual machines.

Best, Krzysztof Kamiński

kkaminski-github avatar Dec 30 '20 14:12 kkaminski-github

Thanks for reporting @kkaminski-github We will take a look and get back in the first week of Jan 2021

ramya-rao-a avatar Dec 31 '20 01:12 ramya-rao-a

Thanks @ramya-rao-a!

I will track this issue to answer any additional questions if they appear ;-)

kkaminski-github avatar Jan 10 '21 17:01 kkaminski-github

@kkaminski-github thanks for reporting this issue and doing the initial investigation. I'm going to be looking at this later today and will update you as soon as I have more information

joheredi avatar Jan 11 '21 19:01 joheredi

Quick update, I got a local repro, currently investigating possible solutions

joheredi avatar Jan 15 '21 19:01 joheredi

@joheredi thanks for your update. Let me know If I can help somehow ;-)

kkaminski-github avatar Jan 18 '21 14:01 kkaminski-github

@kkaminski-github I have a PR out to fix this in ms-rest-js. Which package is the one you were using when found this problem?

joheredi avatar Jan 21 '21 21:01 joheredi

Sure!

From my code:

  getScaleSetWorkers: async () => {

    //TODO: UPGRADE @azure/ms-rest-js before publishing. https://github.com/Azure/ms-rest-js/issues/406
    const result = []; 
    const scaleSetVms = await scaleSetManager.computeClient.virtualMachineScaleSetVMs.list(resourceGroupName, vmSsName);
    result.push(...scaleSetVms);
    let nextLinkToken = scaleSetVms.nextLink;
    while(nextLinkToken){ 
      const scaleSetVmsNext = await scaleSetManager.computeClient.virtualMachineScaleSetVMs.listNext(nextLinkToken);
      result.push(...scaleSetVmsNext);
      nextLinkToken = scaleSetVmsNext.nextLink
    }
    return result;
  },
  

where scaleSetManager.computeClient = new ComputeManagementClient(credentials, subscriptionIdSCP); and const {ComputeManagementClient} = require("@azure/arm-compute");

kkaminski-github avatar Jan 22 '21 11:01 kkaminski-github

Thanks @kkaminski-github! Is @azure/arm-compute the package you are using?

joheredi avatar Jan 25 '21 15:01 joheredi

Yes - as written above ;-)

kkaminski-github avatar Jan 25 '21 16:01 kkaminski-github

Thank you @joheredi for fixing the issue ;-)

kkaminski-github avatar Jan 26 '21 08:01 kkaminski-github