Earlier quoted context omitted.
Yeah, I'm trying to figure out how you even get 20,000 spaces into a Stack Exchange post, and how it would render in your browser.
Browsers typically collapse whitespace, so it probably would render as a single space.
Stack Overflow Outage Postmortem
81–90 of 335 posts
Re: Stack Overflow Outage Postmortem
#82Earlier quoted context omitted.
You can't trust that the user has JavaScript enabled; and since you can't trust user input anyway, you'd have to do this server side.
"You can't trust user input" means to not fudge with user data in the first place! If your code cares about unicode spaces at the beginning of user input, there is your problem. (Also, you missed the reject part)
Re: Stack Overflow Outage Postmortem
#83I don't understand something: the regex expected a space character, followed by the end of the string. If the last character wasn't a space, this could never match. Why did the engine keep backtracking, even though it's easy to figure out that it could never match the regex?
Re: Stack Overflow Outage Postmortem
#84> It took 10 minutes to identify the cause. I'm impressed they were able to do this so quickly.
- login to server
- make dump of all threads stack traces
- see that something like Regexp.match present in all stacks
- find function that called this regexp.
Re: Stack Overflow Outage Postmortem
#85Is this the sort of thing that https://github.com/google/re2 was made to solve?
Re: Stack Overflow Outage Postmortem
#86They implemented trim with a regex? Neither Java nor .NET do that. The postmortem here should probably be "why are you reimplementing trim".
Re: Stack Overflow Outage Postmortem
#87Re: Stack Overflow Outage Postmortem
#88Re: Stack Overflow Outage Postmortem
#89I don't understand something: the regex expected a space character, followed by the end of the string. If the last character wasn't a space, this could never match. Why did the engine keep backtracking, even though it's easy to figure out that it could never match the regex?
Re: Stack Overflow Outage Postmortem
#90I remember the day I learned that Python's "re" module uses backtracking for non-extended regexes. My tests covered lots of corner cases in the regex logic, but were too short for me to notice the performance penalty. Luckily I only caused a partial outage in production. I actually got to talk to Raymond Hettinger (Python core team) about why re uses a potentially exponential-time algorithm for regexes when there is…