ASP.NET 4.0 Changes Control Rendering so that RegEx to Parse ASP.NET Rendered HTML No Longer Works
When trying to find a href tags to update them on the fly in html held in a string, the RegEx that has been working fine for some time has broken since the move from 2.0 to 4.0.
Regex:
<a\\s+[^>]*(href=\"([^#\"]+)\")[^>]*>(.*)</a>
We discount those hrefs with a hash(#) in them because this means they've already been updated but want to return all other instances. The problem comes because now our javascript functions are outputting with '
instead of single quotes which means they fall foul of the test due to the hash(#).
Has there been a change in .Net from 2.0 to 4.0 that would account for this?
UPDATE
Here is what .Net 4.0 is spitting out and has automatically changed the single quotes to '
as mentioned above.
<a class="ctl00_Menu_1 Menu_DynamicMenuItemStyle ctl00_Menu_6" href="javascript:__doPostBack('ctl00$Menu','Menu Parent\\Menu Child')" style="border-style:none;font-size:1em;">Menu Child</a>
Previously, it was outputting the following:
<a class="ctl00_Menu_1 Menu_DynamicMenuItemStyle ctl00_Menu_6" href="javascript:__doPostBack('ctl00$Menu','Menu Parent\\Menu Child')" style="border-style:none;font-size:1em;">Menu Child</a>
This was caught properly by our regex but we've had to update to the following:
@"<a\s+[^>]*(href=\""([^#\""][^\""]+)\"")[^>]*>(.*)</a>"
This now accounts for the newly appearing hashes without screening out those that are encoded as such. I've solved the problem and understand there's been a change although开发者_如何学运维 I'm not 100% where that change has been made. Thanks for the interest.
精彩评论