As part of cleaning up the configuration files in the build script, we have something like this:
Regex.IsMatch(LongStringOfFilecontents, @"Password=""[0-9a-zA-Z]*""")
and
Regex.IsMatch(LongStringOfFilecontents, @"Password2=""[0-9a-zA-Z]*""")
When a match is found, passwords are replaced with a dummy value before the application is released.
The problem is that now it finds "Password", but not "Password2" or "Password1".
This C # .NET 3.5 code has been used for several years, it has been launched hundreds of times and has not been changed. More recently, as a few days ago, it was successfully launched. From this morning he is choking on "Password2". The configuration file really contains both Password = "some arbitrary value" and Password2 = "some arbitrary value".
I suspected that "d2" can be taken as a template, but it is not inside {}, and, as already mentioned, it behaved correctly for several years.
I tested against a possible timeout, and this does not seem to be a problem. I tried the CaseInsensitive option, which doesn't matter anyway ([a-zA-Z], right?), And that also has no effect.
It does not work on two different (Win 7 Professional, 64-bit, SP1) machines, but it works as expected on an XP machine (SP 3).
If this was not the result of this morning automatic update of Windows 7, I was confused.
Here's the full context:
ReplaceInFile(filename, @"Password1=""[0-9a-zA-Z]*""", @"Password1=""REPLACE_ME"""); private static bool ReplaceInFile(string filename, string regexp, string replacement) { try { if (File.Exists(filename)) { string oldContents = null; using (StreamReader reader = new StreamReader(filename, true)) { oldContents = reader.ReadToEnd(); } if (Regex.IsMatch(oldContents, regexp)) { string newContents = Regex.Replace(oldContents, regexp, replacement); if (oldContents != newContents) { File.WriteAllText(filename, newContents); return true; } } else { BuildFailed("DID NOT FIND " + regexp + " in " + filename + " Case-SeNsiTive?"); } } return false; } catch (Exception ex) { BuildFailed(ex.Message); return false; } }
And here is a small part of the large file that he is studying:
<Kirk Enabled="1" Type="8000" Password1="test_pwd" Password2="dev_pwd" UserName1="admin" UserName2="GW-DECT/admin" DutyCycle="1" TcpPort="10000" ServerIP="localhost" />