3 ms·
Side note: /&([^&;]+);/g won't actually parse character entities in HTML correctly. There're a number of corner cases in the HTML5 spec for historical reasons,
by nostrademons 15y ago
Side note: /&([^&;]+);/g won't actually parse character entities in HTML correctly. There're a number of corner cases in the HTML5 spec for historical reasons, and this is one of them. In some cases, it's legal (well, it's a parse error, but the parser must return the specified entity) to leave off the trailing semicolon. Except in attributes, where it depends on what the character following the last character of the entity is. The particular cases are enumerated in a table that is over 2000 lines long.
http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html#consume-a-character-reference http://www.whatwg.org/specs/web-apps/current-work/multipage/...
The example is particularly instructive: ¬it; is parsed as ¬ followed by "it;", but ∉ is parsed as a full entity.
So yes, even for HTML entity parsing (which wasn't the question she was being asked), the correct answer really is "use a library".
- jrockway 15y agoHere's the meat of my point. The correct answer when writing software is "use a library". The correct answer when answering an interview question is code with minimal dependencies.
- paganel 15y ago>Here's the meat of my point. The correct answer when writing software is "use a library". The correct answer when answering an interview question is code with minimal dependencies Which can be paraphrased as: "Here's the meat of my point. The correct answer when building a wooden shack is "use a hammer". The correct answer when answering an interview question about building wooden shacks is to make the hammer first".
- phuff 15y agoWhich can be paraphrased as: "Performance under modern software development interviewing practices has a very low correlation with on the job performance."
- roldon332 15y agoRight, It is an academic exercise, not an attempt to understand how you would actually do the job you are applying for.
- jrockway 15y agoIt's an attempt to understand how you would solve problems of the class that the question is of, not an attempt to get a solution to a specific problem. Not using a library when you should have is a problem solved by a 20 second code review.
- roldon332 15y agoCode reviews are normally done after the developer has spent some time on the code. That is fine that it takes 20 second to determine the code is totally worthless, but the developer has already wasted DAYS of effort.
- yuhong 15y agoExcept in attributes, where it depends on what the character following the last character of the entity is. Yep, the problem here is that people use parameters starting with an ampersand without escaping the ampersand in URLs used in <A HREF=>.