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

PR: Percent encode/decode cwd to encode spaces and special characters #229

Merged
merged 4 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions spyder_terminal/server/logic/term_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import tornado.gen
import tornado.ioloop
from terminado.management import TermManagerBase, PtyWithClients
from urllib.parse import unquote

WINDOWS = os.name == 'nt'

Expand Down Expand Up @@ -70,6 +71,9 @@ def client_disconnected(self, pid, socket):
def create_term(self, rows, cols, cwd=None):
"""Create a new virtual terminal."""
pid = hashlib.md5(str(time.time()).encode('utf-8')).hexdigest()[0:6]
# We need to do percent decoding for reading the info through a cookie
# For further information see spyder-ide/spyder-terminal#225
cwd = unquote(cwd)
pty = self.new_terminal(cwd=cwd, height=rows, width=cols)
pty.resize_to_smallest(rows, cols)
self.consoles[pid] = pty
Expand Down
6 changes: 4 additions & 2 deletions spyder_terminal/server/web/main_handler.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- coding: iso-8859-15 -*-

"""Basic static index.html HTTP handler."""

import tornado.web
import tornado.escape
from os import getcwd
from urllib.parse import quote


class MainHandler(tornado.web.RequestHandler):
Expand All @@ -18,7 +18,9 @@ def initialize(self, db=None):
def get(self):
"""Get static index.html page."""
cwd = self.get_argument('path', getcwd())
self.set_cookie('cwd', cwd)
# We need to do percent encoding for sending the info through a cookie
# For further information see spyder-ide/spyder-terminal#225
self.set_cookie('cwd', quote(cwd))
self.render('../static/build/index.html')

@tornado.gen.coroutine
Expand Down