Skip to content

Commit

Permalink
[GR-46345] Fixed file list encoding.
Browse files Browse the repository at this point in the history
PullRequest: mx/1647
  • Loading branch information
tzezula committed Aug 1, 2023
2 parents 3d9cd65 + d7923ef commit e0577ae
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -15569,6 +15569,9 @@ def __exit__(self, exc_type, exc_value, traceback):
pass

class FileListArchiver:

encoding_error_handler_registered = False

def __init__(self, path, file_list_entry, hash_entry, delegate):
self.path = path
self.file_list_entry = file_list_entry
Expand Down Expand Up @@ -15630,14 +15633,35 @@ def _perm_str(perms):
bit_index -= 1
return perm_str

@staticmethod
def _java_properties_escape(s):
_replacements = {
'\\': '\\\\',
'\n': '\\n',
'\t': '\\t',
':': '\\:',
'=': '\\=',
'#': '\\#',
'!': '\\!',
' ': '\\ '
}
for _old_char, _new_char in _replacements.items():
s = s.replace(_old_char, _new_char)
if not FileListArchiver.encoding_error_handler_registered:
import codecs
codecs.register_error('_java_properties_escape', lambda e: (rf"\u{ord(e.object[e.start]):04x}", e.start + 1))
FileListArchiver.encoding_error_handler_registered = True
return s.encode('ascii', errors='_java_properties_escape').decode("ascii")


def __exit__(self, exc_type, exc_value, traceback):
if self.sha256:
assert self.hash_entry, "Hash entry path must be given"
self._add_entry(self.hash_entry, self.sha256.hexdigest())

if self.filelist is not None:
if self.file_list_entry:
_filelist_str = os.linesep.join([k + ' = ' + self._perm_str(v) for k, v in self.filelist.items()])
_filelist_str = os.linesep.join([self._java_properties_escape(k.replace(os.path.sep, '/')) + ' = ' + self._perm_str(v) for k, v in self.filelist.items()])
self._add_entry(self.file_list_entry, _filelist_str)
if self.path:
_filelist_str = os.linesep.join(self.filelist.keys())
Expand Down Expand Up @@ -18525,7 +18549,7 @@ def alarm_handler(signum, frame):
abort(1, killsig=signal.SIGINT)

# The version must be updated for every PR (checked in CI) and the comment should reflect the PR's issue
version = VersionSpec("6.35.1") # Make module path determinstic if UseModulePath=True is in use.
version = VersionSpec("6.36.0") # Fixed file list encoding

_mx_start_datetime = datetime.utcnow()
_last_timestamp = _mx_start_datetime
Expand Down

0 comments on commit e0577ae

Please sign in to comment.