rod
rod copied to clipboard
Avoid panicking if a bad regexp is returned when hijacking using an incorrect pattern
Using an incorrect pattern (like **.example.com/**
) in the HijackRouter.Add()
method will make the program panic instead of returning an error.
Rod Version: v0.114.5
Error is usually used for uncontrolled contents such as user input, panic is usually used for static content. Usually this regexp pattern is part of the code, so panic is not that unexpected, what do you think?
if it returns the error what would you do with the error?
In this context, I'd expect it to raise an error and halt the execution of program.
You can always check the pattern before you pass it to the code.
_, err := regexp.Compile(reg)
if err != nil {
...
}
router.Add(reg, ...)