Skip to content
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

Fix the summary of converted object types to be treated as HTML #28629

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Menrath
Copy link

@Menrath Menrath commented Jan 6, 2024

Tries to solve #28455

This is me the first time writing Ruby code. Also I didn't have the time to test this and setup a proper development environment. Still I wanted to try to contribute on solving this issue.

Also I am not sure where Mastodon sanitized the HTML for the content (status.text) for non-converted object types. This should also be done here.

@Menrath Menrath force-pushed the patch-2 branch 3 times, most recently from 10c768c to 2e7b916 Compare January 9, 2024 13:35
@ClearlyClaire
Copy link
Contributor

Thanks for your contribution. Mastodon sanitizes the HTML at a later point in the process, so you don't need to sanitize it here.

However, your PR changes how the activities are rendered, without changing the test covering that behavior. They need to be updated as well.

@Menrath Menrath changed the title Converted object types summary (spoiler text) is treated as HTML. Fix the summary of converted object types being treated as HTML. Jan 9, 2024
ClearlyClaire
ClearlyClaire previously approved these changes Jan 9, 2024
@Menrath
Copy link
Author

Menrath commented Jan 9, 2024

I was not too sure, whether including the '\n\n' in the test is the desired behavior. I also added a test for a more typical Event object Mastodon is likely to receive.

- newlines don't have to be escaped
- prefer single quotes strings
- fix missing space after colon
@Menrath
Copy link
Author

Menrath commented Jan 9, 2024

Sorry for all the force pushes, as you squash your pull requests anyway it would have been more clear without them to follow what happened.

@Menrath Menrath changed the title Fix the summary of converted object types being treated as HTML. Fix the summary of converted object types to be treated as HTML. Jan 9, 2024
@Menrath Menrath changed the title Fix the summary of converted object types to be treated as HTML. Fix the summary of converted object types to be treated as HTML Jan 9, 2024
Copy link

codecov bot commented Jan 9, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (5a6d533) 84.75% compared to head (6a59b6f) 84.82%.
Report is 201 commits behind head on main.

Files Patch % Lines
app/lib/activitypub/activity/create.rb 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #28629      +/-   ##
==========================================
+ Coverage   84.75%   84.82%   +0.06%     
==========================================
  Files        1039     1038       -1     
  Lines       28175    28123      -52     
  Branches     4548     4536      -12     
==========================================
- Hits        23881    23854      -27     
+ Misses       3136     3104      -32     
- Partials     1158     1165       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ClearlyClaire ClearlyClaire requested review from a team and Gargron January 10, 2024 10:10
Copy link
Contributor

@ClearlyClaire ClearlyClaire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like a second set of eyes on this, but this looks good to me.

@@ -372,7 +372,8 @@ def in_reply_to_uri
end

def converted_text
linkify([@status_parser.title.presence, @status_parser.spoiler_text.presence, @status_parser.url || @status_parser.uri].compact.join("\n\n"))
title = "<h2>#{@status_parser.title}</h2>" if @status_parser.title.present?
[title, @status_parser.spoiler_text.presence, linkify(@status_parser.url || @status_parser.uri)].compact.join("\n\n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor style thing here ... since we're already in small private methods here, I might pull out a separate method for the title value here (instead of assigning local var) which would return when status_parser.title is blank, or the h2-wrapped value when its present. I'd do similar for the "url || uri" logic - and have this method be just the array of methods/values with the compact + join on the end.


expect(status).to_not be_nil
expect(status.url).to eq 'https://foo.bar/@foo/1234'
expect(strip_tags(status.text)).to eq "Let's change the world\n\nWe meet on January 31st at 8pm in the FooBaar!\n\nhttps://foo.bar/@foo/1234"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both this added coverage and the pre-existing are all using strip_tags in their assertions ... which I think is mostly fine for the purposes we had. That said - since this code is adding the <h2>-wrapped value ... should we assert for its presence (and/or any other ways it may be converted elsewhere?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants