Show More
@@ -25,6 +25,8 b' import tempfile' | |||
|
25 | 25 | from subprocess import Popen, PIPE |
|
26 | 26 | import urllib.parse |
|
27 | 27 | |
|
28 | from rhodecode.lib.str_utils import safe_bytes | |
|
29 | from rhodecode_tools.lib.utils import safe_str | |
|
28 | 30 | from .base import SshVcsServer |
|
29 | 31 | |
|
30 | 32 | log = logging.getLogger(__name__) |
@@ -81,7 +83,7 b' class SubversionTunnelWrapper(object):' | |||
|
81 | 83 | |
|
82 | 84 | def sync(self): |
|
83 | 85 | while self.process.poll() is None: |
|
84 | next_byte = self.stdin.read(1) | |
|
86 | next_byte = self.stdin.buffer.read(1) | |
|
85 | 87 | if not next_byte: |
|
86 | 88 | break |
|
87 | 89 | self.process.stdin.write(next_byte) |
@@ -106,7 +108,7 b' class SubversionTunnelWrapper(object):' | |||
|
106 | 108 | data['url'] = self._svn_string(data['url']) |
|
107 | 109 | data['ra_client'] = self._svn_string(data['ra_client']) |
|
108 | 110 | data['client'] = data['client'] or '' |
|
109 | buffer_ = ( | |
|
111 | buffer_ = safe_bytes( | |
|
110 | 112 | "( {version} ( {capabilities} ) {url}{ra_client}" |
|
111 | 113 | "( {client}) ) ".format(**data)) |
|
112 | 114 | self.process.stdin.write(buffer_) |
@@ -127,21 +129,21 b' class SubversionTunnelWrapper(object):' | |||
|
127 | 129 | return f'{len(str_)}:{str_} ' |
|
128 | 130 | |
|
129 | 131 | def _read_first_client_response(self): |
|
130 | buffer_ = "" | |
|
132 | buffer_ = b"" | |
|
131 | 133 | brackets_stack = [] |
|
132 | 134 | while True: |
|
133 | next_byte = self.stdin.read(1) | |
|
135 | next_byte = self.stdin.buffer.read(1) | |
|
134 | 136 | buffer_ += next_byte |
|
135 | if next_byte == "(": | |
|
137 | if next_byte == b"(": | |
|
136 | 138 | brackets_stack.append(next_byte) |
|
137 | elif next_byte == ")": | |
|
139 | elif next_byte == b")": | |
|
138 | 140 | brackets_stack.pop() |
|
139 | elif next_byte == " " and not brackets_stack: | |
|
141 | elif next_byte == b" " and not brackets_stack: | |
|
140 | 142 | break |
|
141 | 143 | |
|
142 | 144 | return buffer_ |
|
143 | 145 | |
|
144 | def _parse_first_client_response(self, buffer_): | |
|
146 | def _parse_first_client_response(self, buffer_: bytes): | |
|
145 | 147 | """ |
|
146 | 148 | According to the Subversion RA protocol, the first request |
|
147 | 149 | should look like: |
@@ -151,16 +153,20 b' class SubversionTunnelWrapper(object):' | |||
|
151 | 153 | |
|
152 | 154 | Please check https://svn.apache.org/repos/asf/subversion/trunk/subversion/libsvn_ra_svn/protocol |
|
153 | 155 | """ |
|
154 | version_re = r'(?P<version>\d+)' | |
|
155 | capabilities_re = r'\(\s(?P<capabilities>[\w\d\-\ ]+)\s\)' | |
|
156 | url_re = r'\d+\:(?P<url>[\W\w]+)' | |
|
157 | ra_client_re = r'(\d+\:(?P<ra_client>[\W\w]+)\s)' | |
|
158 | client_re = r'(\d+\:(?P<client>[\W\w]+)\s)*' | |
|
156 | version_re = br'(?P<version>\d+)' | |
|
157 | capabilities_re = br'\(\s(?P<capabilities>[\w\d\-\ ]+)\s\)' | |
|
158 | url_re = br'\d+\:(?P<url>[\W\w]+)' | |
|
159 | ra_client_re = br'(\d+\:(?P<ra_client>[\W\w]+)\s)' | |
|
160 | client_re = br'(\d+\:(?P<client>[\W\w]+)\s)*' | |
|
159 | 161 | regex = re.compile( |
|
160 | r'^\(\s{version}\s{capabilities}\s{url}\s{ra_client}' | |
|
161 |
r'\(\s |
|
|
162 | version=version_re, capabilities=capabilities_re, | |
|
163 | url=url_re, ra_client=ra_client_re, client=client_re)) | |
|
162 | br'^\(\s%b\s%b\s%b\s%b' | |
|
163 | br'\(\s%b\)\s\)\s*$' % ( | |
|
164 | version_re, | |
|
165 | capabilities_re, | |
|
166 | url_re, | |
|
167 | ra_client_re, | |
|
168 | client_re) | |
|
169 | ) | |
|
164 | 170 | matcher = regex.match(buffer_) |
|
165 | 171 | |
|
166 | 172 | return matcher.groupdict() if matcher else None |
@@ -202,7 +208,7 b' class SubversionTunnelWrapper(object):' | |||
|
202 | 208 | |
|
203 | 209 | url_parts = urllib.parse.urlparse(first_response['url']) |
|
204 | 210 | |
|
205 | self.server.repo_name = self._match_repo_name(url_parts.path.strip('/')) | |
|
211 | self.server.repo_name = self._match_repo_name(safe_str(url_parts.path).strip('/')) | |
|
206 | 212 | |
|
207 | 213 | exit_code = self.server._check_permissions(action) |
|
208 | 214 | if exit_code: |
General Comments 0
You need to be logged in to leave comments.
Login now