-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mixed line endings not ignored when comparing hashes #247
Comments
So I'm not fully following. If we are ignoring the |
As in, I'm pretty sure once the ignore is in, line endings would no longer be a factor. |
Perhaps an example will help. Think of the following being included in a sql script. -- this line was copied from a unix source.\n Then someone looks at the file in a windows editor and saves it. Now it becomes. -- this line was copied from a unix source.\r\n Function have_same_hash_ignoring_platform in class DefaultDatabaseMigrator will show the file as having been changed and the script will either be run again, or trigger an error or warning when the script should be skipped. |
Again, I'm not sure it would be a factor, that's what ignoring the line endings is about. It doesn't matter if the line ending is windows or unix format, or even older Mac format with |
The enclosed zip file has 4 batch files, and the logs produced by executing those files. Some sql scripts have lines that consistently end in CrLf. Some have lines that consistently end in Lf. And some have lines with a mix of line endings. You should be able to tell which is which from the filenames. Batch files CrLf_Lf and Lf_CrLf run as expected. This shows line endings are ignored when the line endings in individual files are consistent, even if they differ from one file to another. Batch files CrLf_Mixed and Mixed_Crlf show the bug when line endings differ in individual files. |
Curious though, has the other feature actually been released so you can test this? |
Looking at #104 and the ReadMe, it looks like it was released in 0.8.6 - however looking at https://github.com/chucknorris/roundhouse/pull/104/files, it may have a possible bug. I would have expected it to just convert all line endings to one so they would be ignored. |
It comes down to this function, in class DefaultDatabaseMigrator in version 0.8.6.0 which I got from the site a few days ago. I have not looked to see if this has been updated in the unreleased versions.
create_hash(sql_to_run.Replace(line_ending_unix, line_ending_windows)); will produce a mix of \r\r\n and \r\n when sql_to_run has a mix of line endings, explaining why there are problems when the new file has inconsistent endings. If the original file had inconsistent endings, the hash will be based on those endings, so neither substitution will match. |
Right - so it's a bug in the code and the feature. |
I think there are two related bugs. The first is documented above. The code correctly tests if the EOL is unix or windows. However, it returns a false positive when there are both line types intermixed in the same file. The first time through, everything works fine because everything is new. After the first pass, mixed EOL files will consistently be reported as changed by have_same_hash_ignoring_platform even if they haven't been touched. The second bug relates to the hash that is saved and subsequently passed to the above method. We have seen cases where mixed EOL files are repaired "automatically" - by just re-saving a file opened in an editor for example. Some evidence suggests that simply pulling the code from the repo using VS team explorer might actually trigger the "fix". The developer had no intention to make any change, and the SQL database wouldn't detect a change. In order to consistently ignore any EOL changes, the hash that is saved to the database needs to be the one for the EOL-agnostic version of the script - not what is in the current file. I am hoping that after this bug is fixed the -baseline switch could be used to "true up" the hash values in the database without actually executing the SQL code. I can see where this might be a controversial/breaking change so would entertain the introduction of a new switch to enforce this behavior. |
I'm new to this forum and not sure about the next steps. Now that the roundhouse team is aware of the issue, should I leave it in their hands? Or is there more I should do? My original post requested a switch to enable the line endings to be normalized prior to computing the hash to be saved into the database. My testing in the past day shows it would be helpful to edit the function listed above to first change crlf to lf and then change lf to crlf prior to computing the has for the sql_to_run variable. |
I tried not to bring other applications into the discussion, but yes, this issue was noticed in relation to using git with Visual Studio and performing merges. That's a bit much to introduce into a discussion like this one in a reproducible way. |
It goes to the backlog as a bug. |
Then it gets prioritized and fixed - someone from the community could also provide a PR to fix this behavior. |
I'm not ready to enter this as a pull request without real world testing, but I'll mention this solved all of the test cases I entered in my attachment above. It did not require any new switches. I changed function hash in class MD5CryptographicService as listed below. I did not change function have_same_hash_ignoring_platform. However, if this change gets accepted, the line ending changes and multiple hash comparisons in function have_same_hash_ignoring_platform become unnecessary.
|
This is more along the lines of what I would have wanted for the earlier fix. |
This should be addressed by my recent changes to hash computation (on master or the next release). Please reopen with details if what I have doesn't get it done for you. |
This is a follow up to issue: Ignore EOL changes when checking whether script has changed. There is still a problem when the original text has a mix of windows and unix line endings. An attempt is made to convert the new text to all windows line endings and all unix line endings, but neither one matches the original with mixed line endings. I'd like to see a command line switch that lets the user choose to set line endings to all windows or to all unix prior to computing the hash which gets saved to table ScriptsRun. Note, I'm only asking for the hash to be changed to enable future checks to work correctly. I would like the original version of the text to be saved in column text_of_script. If others would like the text to be updated as well, perhaps that could use different values for the switch.
The text was updated successfully, but these errors were encountered: