Hal Canary | 71c3424 | 2019-08-01 11:52:05 -0400 | [diff] [blame] | 1 | #! /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. |
| 5 | import re |
| 6 | import sys |
| 7 | def 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) |
| 16 | if __name__ == '__main__': |
| 17 | sys.stdout.write(gerrit_percent_encode(' '.join(sys.argv[1:])) + '\n') |