Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regular expression does not match #23

Open
jankod opened this issue Mar 10, 2017 · 19 comments
Open

Regular expression does not match #23

jankod opened this issue Mar 10, 2017 · 19 comments

Comments

@jankod
Copy link

jankod commented Mar 10, 2017

I was test on Windows 10 64 bit, with phpstorm on symfony 3.2.5 which produce link like this:

phpstorm://open?file=C:\wamp64\myapp\src\App\Controller\MyController.php&line=29

This line of code does not match:

match = /^phpstorm:\/\/open\?(url=file:\/\/|file=)(.+)&line=(\d+)$/.exec(url),

I was develop new simple version of code that work fine:

var arg = WScript.Arguments(0);

arg = arg.replace("phpstorm://open/?file=", "");
var file=arg.substring(0, arg.indexOf("&"));
var line= arg.substring(arg.indexOf("line=")+5);

var objShell = new ActiveXObject("shell.application"); 
objShell.ShellExecute("C:\\Program Files (x86)\\JetBrains\\PhpStorm 2016.3.2\\bin\\phpstorm64.exe",
"--line "+line+" "+ file);
@aik099
Copy link
Owner

aik099 commented Mar 10, 2017

I've tried original regular exception with your file and it still matches.

What I think might be happening is that URL you think is matched is actually url-encoded or something. Try echoing or something the URL that script gets to detect such issues.

P.S.
The regular expression was changed in #22 recently.

@jankod
Copy link
Author

jankod commented Mar 10, 2017

I have tested regular expresion with JavaScript and work OK, but in JScript host not working.

I was try folowing code and I got null result:

var arg = WScript.Arguments(0);
 
match = /^phpstorm:\/\/open\?(url=file:\/\/|file=)(.+)&line=(\d+)$/.exec(arg);
WSH.Echo("match: "+ match + " URL  '"+ arg + "'");

image

@aik099
Copy link
Owner

aik099 commented Mar 10, 2017

I haven't used Windows for years now, so I have idea what really is wrong, but I'm sure it worked on Windows 7 where I developed original regular expression.

Maybe in Windows 10 some symbols needs to be escaped to get regex working.

@jarro
Copy link

jarro commented Mar 16, 2017

Ran into this as well. What I'm seeing is:
Windows 10 is adding a /

phpstorm://open?file=c 

is changed to

phpstorm://open/?file=c 

tweaked the regex to allow for open/?
if looks okay can make a pull request.

match = /^phpstorm:\/\/open(\?url=file:\/\/|\?file=|\/\?file=)(.+)&line=(\d+)$/.exec(url),

@aik099
Copy link
Owner

aik099 commented Mar 16, 2017

@jankod , please see if fix suggested by @jarro works for you and if so send a PR with it. For such single line change you can do that from GitHub Web UI as well.

@jankod
Copy link
Author

jankod commented Mar 16, 2017

I was tested on Win 10, 64-bit and this regular expresion works OK :)
match = /^phpstorm:\/\/open\/\?(url=file:\/\/|file=)(.+)&line=(\d+)$/.exec(url),

But,
when I run this script, command try to run 32-bit of PhpStorm.exe (not PhpStorm64.exe) which does not work well with me because I do not have 32-bit Java, so I was added this line of code:

var phpStormExe = "PhpStorm.exe"; if(settings.x64 ) { phpStormExe = "PhpStorm64.exe"; }

and change this line:
editor = '"C:\\' + (settings.x64 ? 'Program Files (x86)' : 'Program Files') + '\\JetBrains\\' + settings.folder_name + '\\bin\\'+phpStormExe+'"';

My patch is here master...jankod:patch-1

@jankod jankod closed this as completed Mar 16, 2017
@aik099
Copy link
Owner

aik099 commented Mar 16, 2017

Please don't close the issue until the issue is resolved for others.

And send a PR (only regular expression part). Right now you've made a change in your fork, but haven't send a PR, that can be merged.

@aik099 aik099 reopened this Mar 16, 2017
@jarro
Copy link

jarro commented Mar 16, 2017

@jankod your version of the regex adds support for open/?file but drops support for open?file which might be needed by older versions of windows.

@jankod
Copy link
Author

jankod commented Mar 16, 2017

Yes, I forgot for another Windows version.

maybe it could be a solution something like this, where objItem.Version probably hold OS version number.
But have to tested on another windows version.


var wbemFlagReturnImmediately = 0x10; 
var wbemFlagForwardOnly = 0x20; 
 
var objWMIService = GetObject("winmgmts:\\\\.\\root\\CIMV2"); 
var colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", 
									  wbemFlagReturnImmediately | wbemFlagForwardOnly); 

var enumItems = new Enumerator(colItems); 
for (; !enumItems.atEnd(); enumItems.moveNext()) { 
  var objItem = enumItems.item(); 
 
  // Comment here are Windows 10 64-bit result
  WScript.Echo("Name: " + objItem.Name);  // Microsoft Windows 10
  WScript.Echo("OS Product Suite: " + objItem.OSProductSuite); // 256
  WScript.Echo("OS Type: " + objItem.OSType);   // 18
  WScript.Echo("Version: " + objItem.Version); // 10.0.14393
}

@aik099
Copy link
Owner

aik099 commented Mar 16, 2017

You not just making / optional as we did to add support for alternative url format in #22.

@jarro
Copy link

jarro commented Mar 16, 2017

Don't see any reason to get windows versions involved or change existing behavior.
Just need to add support for the win10 quirk adding an extra slash.
The extra slash doesn't get added if run from command line. Can test the normal behavior there.

match = /^phpstorm:\/\/open(\?url=file:\/\/|\?file=|\/\?file=)(.+)&line=(\d+)$/.exec(url),

can't comment on editor path stuff as I'm using jetbrains toolbox which has a whole different path layout unfortunately.

@jankod
Copy link
Author

jankod commented Mar 16, 2017

Yes, it is good idea for add / character optional.
Something like this will probably work on all Win OS?
I was tested od win 10 and work OK.
match = /^phpstorm:\/\/open[\/]?\?(url=file:\/\/|file=)(.+)&line=(\d+)$/.exec(url),

@jarro
Copy link

jarro commented Mar 16, 2017

that looks even better.

@Wirone
Copy link

Wirone commented Jun 1, 2017

@jarro this is not only Windows 10 issue. I am using Windows 7 and I also had additional /. Adding [\/]? solved matching issue for me.

@aik099
Copy link
Owner

aik099 commented Jun 1, 2017

This was originally developed for Windows 7 and worked there. Probably some nasty Windows Update changed something in how it works.

@malles
Copy link

malles commented Jun 14, 2017

Also encountered this problem, and the regex from @jankod fixed it for me.

@aik099
Copy link
Owner

aik099 commented Jun 14, 2017

So @jankod is any PR coming soon with approved solution from #23 (comment) ?

@jankod
Copy link
Author

jankod commented Aug 27, 2017

Here is my new patch

@aik099
Copy link
Owner

aik099 commented Aug 28, 2017

@jankod , do you plan to send a PR? Also the code you've changed was already changed few days ago in #26.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants