Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove trailing comma from hooks.json and fix SyntaxWarning in Python 3.12 #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions hooks
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ IPTABLES_BINARY = os.getenv('IPTABLES_BINARY') or subprocess.check_output([

# Allow comments in json, copied from https://github.com/getify/JSON.minify
def json_minify(string, strip_space=True):
tokenizer = re.compile('"|(/\*)|(\*/)|(//)|\n|\r')
tokenizer = re.compile(r'"|(/\*)|(\*/)|(//)|\n|\r')
end_slashes_re = re.compile(r'(\\)*$')

in_string = False
Expand All @@ -64,11 +64,12 @@ def json_minify(string, strip_space=True):
# the correct column numbers on parsing errors.
new_str.append(' ' * (match.start() - index))

last_index = index
index = match.end()
val = match.group()

if val == '"' and not (in_multi or in_single):
escaped = end_slashes_re.search(string, 0, match.start())
escaped = end_slashes_re.search(string, last_index, match.start())

# start of string or unescaped quote character to end string
if not in_string or (escaped is None or len(escaped.group()) % 2 == 0): # noqa
Expand Down
2 changes: 1 addition & 1 deletion hooks.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@
"protocol": "udp"
}
]
},
}
}