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
Camofy html image sources #467
Camofy html image sources #467
Changes from 5 commits
4a72f7e
4f20a08
e9a38e7
90aecb4
02b0f95
ad7ba11
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.
don't ask me why I had to put %r{} around it, I just followed rubocop's instructions.
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.
is there any documentaion online that i can use as a guide line for the review?
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.
If you've never seen regexes before, they are a pain in the ass to review. They are kind of like a language in their own right, and the main way to understand regexes is to play around building them and testing them out on a site that shows you what the regex matches.
I've taken the regex here and prepared an example for you: https://regex101.com/r/RLd8UL/1
If you'd like to have a quick online meeting about how to understand this, let me know. I have time tomorrow
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.
I have seen regex before, and it is almost unreadable. thank you for the resource
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.
The best way to test the regex is probably to come up with valid HTML img tags that are not matched by the regex. The edge cases I could think of have been captured in this one.
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.
I am cheating a little bit by using chatgpt, it has some suggestions and explaination, i will check it and comment it
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 one also checks for space in between the elements and has better checking for the imageurl
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.
you seem to have removed the first capturing group. chatgpt has that tendency because it doesn't see you using its result anywhere in your regex. However, we definitely use this capturing group to produce the new text. What I do like, is the use of
\s
; that's any whitespace right?What exactly does the latter part improve? Because I don't think it really improves anything. Let me break my thoughts down:
(.+?)\2( |>|/>)
where\2
matches to the same value as the captured opening quote (either ', " or nothing at all).(.+?)
lazily matches any character. That means that it will begin withsrc='
orsrc="
orsrc=
and then it will continue to match any character until the first time it encounters that same quotation mark again. Subsequently, after the quotation mark, it needs to match one of the three options in( |>|/>)
which are a space, the>
or/>
.([^'">]+)\1(?=[/>])}
where\1
matches the same value as the captured opening quote. Note that[^'">]
is unnecessarily restrictive: I don't know exactly the specification of HTML, but I can image that something likesrc='lookatthisdoublequote"isntitamazing'
is valid. Notice the"
in the middle? Your regex suggestion would stop the src value at that middle quote, because it does not pass the[^'"]
check. And the latter part,(?=[/>])
does not allow for any whitespace.I do have some ideas based on your suggestion:
\s
instead of spaces when I'm indicating whitespacesrc=somesource
, we can only determine the end of the source value when we encounter a whitespace or / or >. But I can change it from( |>|/>)
to( |>|/)
which can be put simpler by writing[ >/]
. However, if I want to match for\s
instead of a space, I can't use the[]
notation, I thinkThere 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.
I've applied the new ideas I mentioned in the latest commit
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 part was my bad "(?=[/>]) does not allow for any whitespace'' i asked chat to remove the whitespace.
I was unaware that this is a valid source "src='lookatthisdoublequote"isntitamazing'", but i can agree that it is to restictive