(filename)
| 2600 | |
| 2601 | # HTML minifier will turn all null bytes into an escaped two-byte sequence "\0". Turn those back to single byte sequences. |
| 2602 | def unescape_nulls(filename): |
| 2603 | data = read_file(filename) |
| 2604 | out = [] |
| 2605 | in_escape = False |
| 2606 | i = 0 |
| 2607 | while i < len(data): |
| 2608 | ch = data[i] |
| 2609 | i += 1 |
| 2610 | if ch == '\\': |
| 2611 | if in_escape: |
| 2612 | out.append('\\\\') |
| 2613 | in_escape = not in_escape |
| 2614 | elif in_escape: |
| 2615 | in_escape = False |
| 2616 | if ch == '0': |
| 2617 | out.append('\x00') # Convert '\\0' (5Ch 00h) into '\0' (00h) |
| 2618 | elif ch == 'x' and data[i] == '0' and data[i + 1] == '0': |
| 2619 | out.append('\x00') # Oddly html-minifier generates both "\\0" and "\\x00", so handle that too. |
| 2620 | i += 2 |
| 2621 | else: |
| 2622 | out.append('\\') |
| 2623 | out.append(ch) |
| 2624 | else: |
| 2625 | out.append(ch) |
| 2626 | |
| 2627 | write_file(filename, ''.join(out)) |
| 2628 | |
| 2629 | unescape_nulls(filename) |
| 2630 |
no test coverage detected