# Buggy code
def files_in_archive(self, force_refresh=False):
    if self._files_in_archive and not force_refresh:
        return self._files_in_archive

    cmd = [self.cmd_path, "--list", "-C", self.dest]
    if self.zipflag:
        cmd.append(self.zipflag)
    if self.opts:
        cmd.extend(["--show-transformed-names"] + self.opts)
    if self.excludes:
        cmd.extend(["--exclude=" + f for f in self.excludes])
    cmd.extend(["-f", self.src])
    rc, out, err = self.module.run_command(
        cmd, cwd=self.dest, environ_update=dict(LANG="C", LC_ALL="C", LC_MESSAGES="C")
    )
    if rc != 0:
        raise UnarchiveError("Unable to list files in the archive")

    for filename in out.splitlines():
        # Compensate for locale-related problems in gtar output (octal unicode representation) #11348
        # filename = filename.decode('string_escape')
        filename = to_native(codecs.escape_decode(filename)[0])

        # We don't allow absolute filenames.  If the user wants to unarchive rooted in "/"
        # they need to use "dest: '/'".  This follows the defaults for gtar, pax, etc.
        # Allowing absolute filenames here also causes bugs: https://github.com/ansible/ansible/issues/21397
        if filename.startswith("/"):
            filename = filename[1:]

        exclude_flag = False
        if self.excludes:
            for exclude in self.excludes:
                if fnmatch.fnmatch(filename, exclude):
                    exclude_flag = True
                    break

        if not exclude_flag:
            self._files_in_archive.append(to_native(filename))

    return self._files_in_archive


# Traceback (nUnicodeEncodeError)
TASK [unarchive : test that unarchive works with an archive that contains non-ascii filenames] **************************************************************************
fatal: [testhost]: FAILED! => {"changed": false, "module_stderr": "Shared connection to localhost closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/root/.ansible/tmp/ansible-tmp-1561576726.3763218-37161750934991/AnsiballZ_unarchive.py\", line 139, in <module>\r\n    _ansiballz_main()\r\n  File \"/root/.ansible/tmp/ansible-tmp-1561576726.3763218-37161750934991/AnsiballZ_unarchive.py\", line 131, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/root/.ansible/tmp/ansible-tmp-1561576726.3763218-37161750934991/AnsiballZ_unarchive.py\", line 65, in invoke_module\r\n    spec.loader.exec_module(module)\r\n  File \"<frozen importlib._bootstrap_external>\", line 678, in exec_module\r\n  File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed\r\n  File \"/tmp/ansible_unarchive_payload_o9_x930g/__main__.py\", line 909, in <module>\r\n  File \"/tmp/ansible_unarchive_payload_o9_x930g/__main__.py\", line 859, in main\r\n  File \"/usr/local/lib/python3.6/genericpath.py\", line 42, in isdir\r\n    st = os.stat(s)\r\nUnicodeEncodeError: 'ascii' codec can't encode characters in position 51-54: ordinal not in range(128)\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

# Fixed code
def files_in_archive(self, force_refresh=False):
    if self._files_in_archive and not force_refresh:
        return self._files_in_archive

    cmd = [self.cmd_path, "--list", "-C", self.b_dest]
    if self.zipflag:
        cmd.append(self.zipflag)
    if self.opts:
        cmd.extend(["--show-transformed-names"] + self.opts)
    if self.excludes:
        cmd.extend(["--exclude=" + f for f in self.excludes])
    cmd.extend(["-f", self.src])
    rc, out, err = self.module.run_command(
        cmd, cwd=self.b_dest, environ_update=dict(LANG="C", LC_ALL="C", LC_MESSAGES="C")
    )

    if rc != 0:
        raise UnarchiveError("Unable to list files in the archive")

    for filename in out.splitlines():
        # Compensate for locale-related problems in gtar output (octal unicode representation) #11348
        # filename = filename.decode('string_escape')
        filename = to_native(codecs.escape_decode(filename)[0])

        # We don't allow absolute filenames.  If the user wants to unarchive rooted in "/"
        # they need to use "dest: '/'".  This follows the defaults for gtar, pax, etc.
        # Allowing absolute filenames here also causes bugs: https://github.com/ansible/ansible/issues/21397
        if filename.startswith("/"):
            filename = filename[1:]

        exclude_flag = False
        if self.excludes:
            for exclude in self.excludes:
                if fnmatch.fnmatch(filename, exclude):
                    exclude_flag = True
                    break

        if not exclude_flag:
            self._files_in_archive.append(to_native(filename))

    return self._files_in_archive