Skip to content

Slashes in folder param become escaped #1351

Closed

Description

@Merith-TK
Version: 1.41.1
Commit: f51e045cd5483561afc07694f39307fb673b6d1d
Date: 2020-01-17T22:58:55.612Z
Browser: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
Code Server Version: 2.1698-vsc1.41.1
  • OS Version: archlinux

Description

When changing directories, it becomes
https://code.example.com/?folder=vscode-remote%3A%2F%2Fcode.example.com%2Fhome%2Fdeveloper%2FWorkspace%2FDND
instead of `https://code.example.com/?folder=/home/developer/Workspace/

Steps to Reproduce

  1. open folder as default (accessible at https://example.com/)
  2. CTRL+k and CTRL+O and open a different folder
  3. check url

Activity

  1. Merith-TK commented on Feb 10, 2020

    @Merith-TK
    ContributorAuthor

    yes i know the name of the issue is horrible, my words have been failing me today

  2. changed the title [-]Url changes to non-standard output when changing directories[/-] [+]Slases in folder param become escaped for no reason[/+] on Feb 11, 2020
  3. nhooyr commented on Feb 11, 2020

    @nhooyr
    Contributor

    Fixed :)

    Thanks for reporting, I confirmed this.

  4. changed the title [-]Slases in folder param become escaped for no reason[/-] [+]Slashes in folder param become escaped[/+] on Feb 11, 2020
  5. Merith-TK commented on Feb 11, 2020

    @Merith-TK
    ContributorAuthor

    Yeah, also whats with the ?folder=vscode-remote%3A%2F%2Fcode.example.com%2F instead of ?folder=/

    I dont understand why it does this?

  6. nhooyr commented on Feb 11, 2020

    @nhooyr
    Contributor

    Not sure either. cc @code-asher.

  7. code-asher commented on Feb 11, 2020

    @code-asher
    Member

    I'm not certain, that just seems to be what VS Code 1.41.1 is doing now.

  8. code-asher commented on Feb 11, 2020

    @code-asher
    Member

    To clarify, if you click file > open that's what VS Code puts in the URL, so I updated our server code to match.

  9. Merith-TK commented on Feb 11, 2020

    @Merith-TK
    ContributorAuthor

    i think it may be because of the implementation?
    This suggests that code-server uses a varient of the vscode-remote extension and wasnt properly modifed

  10. code-asher commented on Feb 11, 2020

    @code-asher
    Member

    Internally VS Code refers to remote files with the vscode-remote:// scheme. In our case the remote provider is code-server but that doesn't change the scheme that VS Code uses. We could change it (and we used to) but there didn't seem any benefit in the added patching it required.

  11. Merith-TK commented on Feb 11, 2020

    @Merith-TK
    ContributorAuthor

    Ah, alright then,

  12. coadler commented on Feb 11, 2020

    @coadler
    Contributor

    Aren't slashes supposed to be URL encoded in query strings?

  13. nhooyr commented on Feb 11, 2020

    @nhooyr
    Contributor

    It's optional.

    package main
    
    import (
    	"fmt"
    	"net/url"
    )
    
    func main() {
    	u, _ := url.Parse("localhost:8080/?meow=bar/foo&big=coadler/asher")
    	fmt.Println(u.Query())
    }

    Prints:

    map[big:[coadler/asher] meow:[bar/foo]]
    
  14. coadler commented on Feb 11, 2020

    @coadler
    Contributor

    That's true it parses, but there'd be no way to construct the same thing on the way out

    package main
    
    import (
    	"fmt"
    	"net/url"
    )
    
    func main() {
    	u, err := url.ParseQuery("meow=bar/foo&big=coadler/asher")
    	if err != nil {
    		panic(err)
    	}
    	
    	fmt.Println(u)
    	fmt.Println(u.Encode())
    }
    map[big:[coadler/asher] meow:[bar/foo]]
    big=coadler%2Fasher&meow=bar%2Ffoo
    

    https://tools.ietf.org/html/rfc2396#section-3.4 seems to indicate slashes are reserved within query strings

    The documentation for ParseQuery says that it expects a URL-encoded query string but seems to work fine if it doesn't
    https://golang.org/src/net/url/url.go?s=25201:25246#L859

  15. nhooyr commented on Feb 11, 2020

    @nhooyr
    Contributor

    That's interesting. So then everything is working as expected.

    @code-asher Why does the folder argument need the scheme when it's always vscode-remote? Let's just remove it and add it ourselves when appropriate?

  16. code-asher commented on Feb 12, 2020

    @code-asher
    Member
  17. JtMotoX commented on Mar 10, 2020

    @JtMotoX

    I navigate many times by manually editing the url to open the folder I want. It also helps me easily see the directory that I am currently in, since many times I will have 5 tabs open with different directories. The new vscode-remote:// URL has been pretty annoying. I wish there were a way to keep the folder= URL or at least an option or parameter we can pass when launching code-server.

    Workaround to give you the old url functionality back:
    My code-server instance sits behind a nginx reverse proxy with Let's Encrypt SSL and a secure username+pwd login form. If anyone has their instance behind an nginx reverse proxy, you can add the configuration lines below to your nginx configs which will strip out the vscode-remote:// and replace the characters with slashes which will give you the url format that we are all used to. Each additional line will support 1 subdirectory deep, so my configs below will support 12 subfolders deep. There may be a better way of doing this but I am new to nginx and only have about 10 hours of experience with it, 2 of which were spent trying to solve this.

    This:
    https://my.domain.com/?folder=vscode-remote%3A%2F%2Fmyhostname%2FUsers%2Fusername%2Ffolder1%2Ffolder2%2Ffolder3
    Becomes This:
    https://my.domain.com/?folder=/Users/username/folder1/folder2/folder3

        set $args_original $args;
        if ($args ~ ^(folder=)vscode-remote%3A%2F%2F.*?%2F(.*)$) { set $args $1/$2; }
        if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
        if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
        if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
        if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
        if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
        if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
        if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
        if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
        if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
        if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
        if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
        if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
        if ($args != $args_original) {
            return 301 "$scheme://${http_host}$uri?$args";
        }
    
  18. code-asher commented on Mar 10, 2020

    @code-asher
    Member
  19. Merith-TK commented on Mar 10, 2020

    @Merith-TK
    ContributorAuthor

    how easy would that patch be?

  20. code-asher commented on Mar 11, 2020

    @code-asher
    Member
  21. code-asher commented on Mar 11, 2020

    @code-asher
    Member
  22. JtMotoX commented on Mar 11, 2020

    @JtMotoX

    That sounds great!

  23. JtMotoX commented on Mar 11, 2020

    @JtMotoX

    I imagine it would be a single line change

    30 lines later...

    closed this in 26647c5

    Thanks Asher! 👏

  24. code-asher commented on Mar 16, 2020

    @code-asher
    Member

    I think we're going to need to revert this (at least re-introduce the encoding) because otherwise you can't open directories with #, &, etc to name a few.

  25. code-asher commented on Mar 16, 2020

    @code-asher
    Member

    Hmm maybe we can decode just the slashes after encoding (.replace("%2F", "/")). Seems to work but I'm not sure if there's some case I'm not considering.

  26. t-d-d commented on Apr 6, 2020

    @t-d-d

    @code-asher and can't open paths with spaces which is fairly common. See #1488

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions