Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
[Security Solution] Adds diff algorithm and unit tests for multi-line string fields #188022
[Security Solution] Adds diff algorithm and unit tests for multi-line string fields #188022
Changes from 2 commits
dd44bf0
cf9c64c
17f4cf6
a20616a
8ae425f
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was our ultimate decision on such cases? Are we going to mark these potential ABC situations as
SOLVABLE_CONFLICT
later to let users explicitly accept our merge proposal?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is what I'm currently working on: #187770
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it's a legitimate concern, but it looks like we are substituting all whitespace chars (except newlines) with spaces when we do
.join(' ')
. I wonder if it can mess up formatting if someone had tab chars in property values.I think you can't insert a tab or another weird whitespace char when editing via our web UI, but maybe you can if you edit it an external editor.
I played with it a little and tried to come up with a regexp that won't consume whitespace chars so that we won't have to "restore" them later. This is what I came up with:
It does split the string correctly. For example this string
gets split as
BUT for some reason
merge
still returns a conflict when I try to run it withI expected it merge without conflict and return
@dplumlee Any idea why might that be? Am I misunderstanding how it works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fair question, I was thinking about it when initially toying with the regex. I think the only true way around it would be to make one that gets split with all the whitespace still in tact (e.g. something like
['First ', 'line.\n', 'Second<space character>', 'line.'])
so we could.join
with no argument and just merge the strings back together with their appending whitespace attached at the hip. None of these fields will be impactful to rule runs themselves so I'm also unsure of it's a big concern but I suppose it has the potential to mess with markdown stuff made via third party (although by default markdown only uses spaces so far as I can tell).For that particular example, I've been trying to get it to work for a bit - might be the case that the package is just not sophisticated enough to handle it. Or we need better regex as described above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Played with it a bit more and think I came up with a cleaner regexp that does exactly this:
/(?<=\s)(?=\S)/
Still the
returns a computated merged version without a conflict if 3 way merge is possible
test doesn't pass. Becausemerge
returns a conflict when I expect it to merge cleanly. Not sure why.Do you have an idea why might that not work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please disregard most of my above comment. The
/(?<=\s)(?=\S)/
regexp actually does work and tests do pass with it! I modified the test implementation, that's why I saw the error 🤦♂️. If you use/(?<=\s)(?=\S)/
asstringSeparator
and then do.join('')
it should work fine. And this way it won't cut away non-space chars.Also I think I found the limitation of the diffing lib. It can't merge without a conflict if changed sections are adjacent.
For example, this merges cleanly:
While this results in a conflict:
But there's nothing we can do about it. Please try the new regexp approach and tell me what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @dplumlee and @nikitaindik
I've been doing some additional testing and came up with:
stringSeparator: /(\S+|\s+)/g,
plus using.join('')
.This allowed the algorithm to both:
Both of the next two examples pass:
1.
2.