Skip to content

Commit c3b2334

Browse files
Update doscript.py
1 parent bc92bdd commit c3b2334

1 file changed

Lines changed: 41 additions & 5 deletions

File tree

doscript.py

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/usr/bin/env python3
22
"""
3-
DoScript v0.6.5 - Execute EXE files
3+
DoScript v0.6.6 - Fixed URL parsing bug
44
Changes:
5+
- Fixed comment parser to not break URLs with // inside quoted strings
6+
7+
Previous version (0.6.5):
58
- execute: Execute .exe files directly
69
710
Previous version (0.6.4):
@@ -58,7 +61,7 @@
5861
HAS_PSUTIL = False
5962

6063
# Current interpreter version
61-
VERSION = "0.6.5"
64+
VERSION = "0.6.6"
6265

6366
# ----------------------------
6467
# Script Template
@@ -498,16 +501,49 @@ def parse_script(self, filename: str) -> List[str]:
498501
out: List[str] = []
499502
cur = ""
500503
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)
504506
line = line.rstrip('\n\r')
505507
t = line.strip()
506508
if t:
507509
cur += (" " + t) if cur else t
508510
out.append(cur)
509511
cur = ""
510512
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)
511547

512548
def extract_string(self, s: str) -> str:
513549
s = s.strip()

0 commit comments

Comments
 (0)