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

URI toString() percent-encodes colon symbol after drive letter (MS Win 10) #2990

Closed
lfurzewaddock opened this issue Feb 12, 2016 · 6 comments
Assignees
Labels
api bug Issue identified by VS Code Team member as probable bug verified Verification succeeded
Milestone

Comments

@lfurzewaddock
Copy link

While developing an MS VS Code extension in JavaScript, I encountered this unexpected behaviour while accessing the URI of the current document open in the editor;

editor.document.uri.toString()

Returns invalid MS Win 10 file URI

"file:///d%3A/Dir/VS-Code/Extensions/vscode-opn/temp/index.html"

When it should return a valid MS Win 10 file URI

"file:///d:/Dir/VS-Code/Extensions/vscode-opn/temp/index.html"

Code Snippet;

var editor = vscode.window.activeTextEditor;

// Bug workaround
if (editor.document.uri.scheme.toString() === 'file') {
  opn('file://'+editor.document.uri.path.toString());
}
else {
  opn(editor.document.uri.toString()); 
}
@jrieken
Copy link
Member

jrieken commented Mar 11, 2016

@lfurzewaddock As a workaround you should use fsPath (which also handles network shares). The real fix is to use a 'scheme'-dependent encoding. Fixing this might have unwanted consequences because we use the URI often as a key in persisted storage

@lfurzewaddock
Copy link
Author

OK @jrieken, fsPath will work on all 3 platforms (Win, Mac and Linux) too?

Out of interest if I implemented 'scheme'-dependent encoding locally for my extension, I would check editor.document.uri.scheme.toString() then encode which property? In other words which property holds the raw/untouched path, recommended to be encoded depending on the scheme to work on all platforms?

@jrieken
Copy link
Member

jrieken commented Mar 11, 2016

Yes, fsPath is the one use for fs operations. It's also honors UNC share paths were windows paths are made up from a authority and path, like file://shares/file/stuff is \\shares\file\stuff where the path is just /file/stuff and auth is shares.

@jrieken
Copy link
Member

jrieken commented Mar 11, 2016

I afraid that the raw path as given to parse isn't stored but only the uri components

@jrieken
Copy link
Member

jrieken commented Mar 31, 2016

Idea is that Uri#toString will take a parameter that controls to what degree encoding happens. If not wished only what is required to parse into the same result again is encoded, a sample would be the #-character inside a path: file:///pröjects/c#/file.cs#l=12 will toString like this: file:///pröjects/c%23/file.cs#l=12

@jrieken
Copy link
Member

jrieken commented Apr 1, 2016

With 65cb339 I pushed a change that allows you to skipEncoding when calling URI.toString. That or fsPath should be sufficient when talking to other applications/systems

@jrieken jrieken closed this as completed Apr 1, 2016
@jrieken jrieken assigned joaomoreno and unassigned jrieken Apr 28, 2016
@joaomoreno joaomoreno added the verified Verification succeeded label Apr 29, 2016
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api bug Issue identified by VS Code Team member as probable bug verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

3 participants