1

If I set my program to echo command arguments and run in Visual Studio debugger with Command Arguments "https%3a%2f%2fas" it will echo 'https://as'

However, if I run from the command line 'myprog.exe https%3a%2f%2fas' then it will echo 'https%3a%2f%2fas'

Why is it handling this differently, and how can I stop it? I have to pass in an argument that is URL encoded and it needs to not be interpreted by Visual Studio first.

Program is C++ and it's Visual Studio 2017 if that is any help.

Andy Krouwel
  • 1,309
  • 11
  • 21
  • Hi Andy, any update for this issue? If you've reported the issue to product team, you can share the link here, so that we can vote for it and follow it. And you can check if my workaround helps, just a reminder:) – LoLance Jul 04 '19 at 01:33
  • https://developercommunity.visualstudio.com/content/problem/630271/visual-studio-decodes-url-encoded-command-argument.html – Andy Krouwel Jul 04 '19 at 10:29
  • I am going to implement a slight variant on fix 3 - add a parameter to say 'get arguments from a file' so I keep the ability to run from command line or debugger. This has the other advantage that I can keep the debugger arguments in source control. – Andy Krouwel Jul 04 '19 at 10:31
  • Hi Andy, I checked the content from the link you shared. It seems this behavior is something like a built-in behavior by design. Sorry for the inconvenience it makes to you, my suggestion is that you can Go Help=>Send Feedback=>Provide a suggestion to report the latest two suggestions from your comment as a suggestion-format. `updated the document about Command-line argument page or add a feature to control URL decoding`. – LoLance Jul 08 '19 at 08:39
  • The problem is even worse than this: Visual Studio will urldecode *any* command argument, including filenames. And it will *also* urldecode the starting directory, which obviously cannot be a URL ever. VS2019, but I cannot report the error anymore (out of support when I try). – MSalters Aug 18 '23 at 13:47

1 Answers1

0

Can I stop Visual Studio URL decoding Command Arguments in Debug mode?

Sorry but I'm afraid the answer is negative. This issue does exist after my test, and as far as I know there is no option in VS now can turn off or control this behavior. For this, I suggest you can Go Help=>Send Feedback=>Report a problem in VS to report this issue to product team.

I have to pass in an argument that is URL encoded and it needs to not be interpreted by Visual Studio first.

And since it works well in command-line. So what you need is to get the UrlEncode format string during the VS debug process in your development. For this you can try:

1.Add some code before where you need the real argument to UrlEncode the argv[1](I think it's https://as). About how to do UrlEncode see this issue.

2.Set the argument in this way, set https% 3a% 2f% 2fasas the argv[1] instead of https%3a%2f%2fas in project properties, then add code to judge if it contains space, if true=>write code to remove the space in it and get a new string you want (https%3a%2f%2fas)

3.Configure your custom Argument file:

1# In vs, right-click the project=>add a Text.txt file into project.

2# Set the only argument in this as Text.txt.

enter image description here

Then the content of your Text.txt is the collection of your custom arguments. For example:

In the line1 of Text.txt file is https%3a%2f%2fas, line2 is test, line3 is...

enter image description here

3# Then you can use code like this:

#include "pch.h"
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main(int argc, char* argv[])
{
    ifstream infile(argv[1]); //open the file

    string MyArgus[10]; //create my alternative argus
    MyArgus[0] = argv[0]; //let the first argu of Myargus=original vs argu[0]
    if (infile.is_open() && infile.good()) {
        cout << "File is open."<<endl;
        string line = "";

        int num = 1;
        while (getline(infile, line)) {
            MyArgus[num] = line;
            num++;
        }
    }
    else {
        cout << "Failed to open file..";
    }

    cout << MyArgus[0]<<endl; // projectName.exe always
    cout << MyArgus[1]<<endl; // https%3a%2f%2fas
    cout << MyArgus[2]<<endl; // test
    return 0;
}

So you can write arguments in this way in Text.txt file to set your custom arguments to avoid the auto UrlDecode in VS.

Hope it helps:)

LoLance
  • 25,666
  • 1
  • 39
  • 73