Regex for iteration/case 0 breaks on filename with special characters
krackers opened this issue · 2 comments
Hi, thanks for your work in this. I noticed that the script silently breaks when the filename has special characters like !
inside it. Here is a minimal example
package main
import (
"fmt"
"regexp"
)
func main() {
raw := `document.getElementById('dlbutton').href = "/d/EP04EZxQ/" + (597700 % 51245 + 597700 % 913) + "/!.txt";`
r := regexp.MustCompile(`document\.getElementById\('dlbutton'\)\.href\s*=\s*"/d/(\w+)/"\s*\+\s*([\d\w\s+\-*/%()]+?)\s*\+\s*"/([/\w%.-]+)";?`)
m := r.FindStringSubmatch(raw)
fmt.Println(m)
}
The reason is the last regex [/\w%.-]+
which breaks with a filename of !.txt
. !
is a valid identifier in the URLs. So maybe we should just make it .+
instead? This holds for iteration/cases 1 and 3 as well.
I would also like to provide some suggestions to make the code more readable:
- Use raw string in the regexp so that you don't need to do multiple layers of escaping
- Inside TryMakeZippyFile, print a message when all iterations fail instead of silently exiting
This looks great, I'll write up the fix in a second and look at the suggestions too!
I never knew Golang had raw string literals, the project was pretty much me learning GoLang, so new features surprise me each day
Please don't hesitate to reach out if the PR was unsatisfactory.