blob: f850c088e73ffe295a2e636d9e22106b0ac83051 [file] [log] [blame]
Hal Canary71c34242019-08-01 11:52:05 -04001#! /usr/bin/env python
2# Copyright 2019 Google LLC.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5import re
6import sys
7def gerrit_percent_encode(value):
8 '''
9 https://gerrit-review.googlesource.com/Documentation/user-upload.html
10 "To avoid confusion in parsing the git ref, at least the following characters
11 must be percent-encoded: " %^@.~-+_:/!". Note that some of the reserved
12 characters (like tilde) are not escaped in the standard URL encoding rules..."
13 '''
14 good = re.compile('^[A-Za-z0-9]$')
15 return ''.join(c if good.match(c) else '%%%02X' % ord(c) for c in value)
16if __name__ == '__main__':
17 sys.stdout.write(gerrit_percent_encode(' '.join(sys.argv[1:])) + '\n')