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