|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | """ |
3 | | -DoScript v0.6.5 - Execute EXE files |
| 3 | +DoScript v0.6.6 - Fixed URL parsing bug |
4 | 4 | Changes: |
| 5 | +- Fixed comment parser to not break URLs with // inside quoted strings |
| 6 | +
|
| 7 | +Previous version (0.6.5): |
5 | 8 | - execute: Execute .exe files directly |
6 | 9 |
|
7 | 10 | Previous version (0.6.4): |
|
58 | 61 | HAS_PSUTIL = False |
59 | 62 |
|
60 | 63 | # Current interpreter version |
61 | | -VERSION = "0.6.5" |
| 64 | +VERSION = "0.6.6" |
62 | 65 |
|
63 | 66 | # ---------------------------- |
64 | 67 | # Script Template |
@@ -498,16 +501,49 @@ def parse_script(self, filename: str) -> List[str]: |
498 | 501 | out: List[str] = [] |
499 | 502 | cur = "" |
500 | 503 | for line in raw: |
501 | | - # remove comments (note: simplistic - removes everything after # or //) |
502 | | - line = re.sub(r'#.*$', '', line) |
503 | | - line = re.sub(r'//.*$', '', line) |
| 504 | + # remove comments (quote-aware - don't remove # or // inside strings) |
| 505 | + line = self._remove_comments(line) |
504 | 506 | line = line.rstrip('\n\r') |
505 | 507 | t = line.strip() |
506 | 508 | if t: |
507 | 509 | cur += (" " + t) if cur else t |
508 | 510 | out.append(cur) |
509 | 511 | cur = "" |
510 | 512 | return out |
| 513 | + |
| 514 | + def _remove_comments(self, line: str) -> str: |
| 515 | + """Remove comments but preserve # and // inside quoted strings""" |
| 516 | + result = [] |
| 517 | + in_double_quote = False |
| 518 | + in_single_quote = False |
| 519 | + i = 0 |
| 520 | + while i < len(line): |
| 521 | + char = line[i] |
| 522 | + |
| 523 | + # Track quote state |
| 524 | + if char == '"' and not in_single_quote and (i == 0 or line[i-1] != '\\'): |
| 525 | + in_double_quote = not in_double_quote |
| 526 | + result.append(char) |
| 527 | + elif char == "'" and not in_double_quote and (i == 0 or line[i-1] != '\\'): |
| 528 | + in_single_quote = not in_single_quote |
| 529 | + result.append(char) |
| 530 | + # Check for comments outside quotes |
| 531 | + elif not in_double_quote and not in_single_quote: |
| 532 | + if char == '#': |
| 533 | + # Rest of line is comment |
| 534 | + break |
| 535 | + elif char == '/' and i + 1 < len(line) and line[i + 1] == '/': |
| 536 | + # Rest of line is comment |
| 537 | + break |
| 538 | + else: |
| 539 | + result.append(char) |
| 540 | + else: |
| 541 | + # Inside quotes, keep everything |
| 542 | + result.append(char) |
| 543 | + |
| 544 | + i += 1 |
| 545 | + |
| 546 | + return ''.join(result) |
511 | 547 |
|
512 | 548 | def extract_string(self, s: str) -> str: |
513 | 549 | s = s.strip() |
|
0 commit comments