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

AO3-6626: stop tags from being added with Chinese or Japanese commas #4663

Merged
merged 6 commits into from
Dec 4, 2023

Conversation

kwerey
Copy link
Contributor

@kwerey kwerey commented Nov 17, 2023

Hi! First time looking at the AO3 codebase - I wanted to learn a bit about Ruby and I'm a happy AO3 user so I set up an AO3 dev env and rummaged around Jira a little. Here is a very simple change for an existing ticket, please let me know if I'm missing anything.

Pull Request Checklist

Issue

(https://otwarchive.atlassian.net/jira/software/c/projects/AO3/issues/AO3-6626)

Purpose

This pull request adds two additional characters to the regex of forbidden characters

Testing Instructions

The Archive's QA team can verify that this is working as intended by following the test steps set out in the Jira ticket, copy/pasted here:

Log in as a tag wrangler (e.g., testy)

Create a new tag with a Chinese ( , ) or Japanese (、) comma

    Browse > Tags > New Tag

    In the Name field, enter a tag name that contains one of the commas 

        Both Tag With 、Japanese Comma and Tag With ,Chinese Comma have been created on staging

    Select a Category, e.g., Additional Tag

    Check the Canonical checkbox

    Press Create Tag

Try to use the tag in an autocomplete field

    Post > New Work

    Fill in required fields

    In the appropriate tag field, enter the name of the tag you created in Step 2, or choose it from the autocomplete

    Press Post

I have tested this on a local Docker environment. I did not add a unit test because there's already an appropriate-looking unit test for the forbidden character filter, which currently passes:

  it "should not be valid with disallowed characters" do
    tag = Tag.new
    tag.name = "bad<tag"
    expect(tag.save).to be_falsey
    expect(tag.errors[:name].join).to match(/restricted characters/)
  end

Which currently passes:

Run options: include {:locations=>{"./spec/models/tag_spec.rb"=>[171]}}

Tag
  should not be valid with disallowed characters

Finished in 5.17 seconds (files took 5.43 seconds to load)
1 example, 0 failures

References

No other relevant issues/pull requests/mailing list discussions.

Credit

What name and pronouns should we use to credit you in the Archive of Our Own's Release Notes?

username: kwerey
pronouns: they/them

I do not currently have a public Jira account.

@kwerey
Copy link
Contributor Author

kwerey commented Nov 17, 2023

I'm happy to fix the styleguide comment, but I'm not really clear what it's asking me to change - Github Actions here seems to give different output than I get from running it locally with: docker-compose run --rm test bundle exec rubocop app/models/tag.rb (where I get 304 offenses detected but no entry for the line I've changed).

I'll not push another commits so as to avoid running these other fairly long build jobs but very happy to tweak stuff on request. Thanks!

@Bilka2
Copy link
Contributor

Bilka2 commented Nov 19, 2023

Hey, thank you for contributing to this repository! Usually someone from the OTW says hello to new contributors, but I figured I'd already comment on the Rubocop warnings. (I'm an outside contributor, not part of the OTW.)

When I run the command you pasted, it reports 304 offenses, with 2 of them on line 171 which was changed by this PR:

app/models/tag.rb:171:5: C: [Correctable] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
    with:    /\A[^,,、*<>^{}=`\\%]+\z/, ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/tag.rb:171:5: C: [Correctable] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
    with:    /\A[^,,、*<>^{}=`\\%]+\z/,
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Only the Layout/HashAlignment offense is directly caused by the changes here, due to the extra spaces added in front of the regular expression.

However, this PR is a good opportunity is fix both the offenses above as well as this one:

app/models/tag.rb:170:3: C: [Correctable] Rails/Validation: Prefer the new style validations validates :column, format: value over validates_format_of.
  validates_format_of :name,
  ^^^^^^^^^^^^^^^^^^^

Applying these suggestions would result in:

  validates :name,
            format: { with: /\A[^,,、*<>^{}=`\\%]+\z/,
                      message: "^Tag name '%{value}' cannot include the following restricted characters: , &#94; * < > { } = ` , 、 \\ %" }

I think it would be good to make these changes.

@kwerey kwerey force-pushed the AO3-6626/tag-characters branch from 41c11fb to a5b6a3c Compare November 19, 2023 17:50
@kwerey
Copy link
Contributor Author

kwerey commented Nov 19, 2023

Thank you for useful guidance! I've made those corrections and adjusted some the other validation statements in this block to match the format that it recommends.

Edit: I fixed the Rubocop issue, but two different Cucumber tests failed on two different commits, one about unmarking comments as spam, one about navigating between works. I ran both the specific failing tests a few times locally and didn't see the same failure. Is there something I can do to sort that out? IIRC there's a "Rerun only failed tests" option in Github Actions but I think the only way I can retrigger tests is by pushing a new commit, and it seems a little wasteful to retrigger pipelines again without changing anything else or understanding the failure mode here.

@kwerey kwerey force-pushed the AO3-6626/tag-characters branch from a5b6a3c to 250b48f Compare November 19, 2023 22:18
@sarken
Copy link
Collaborator

sarken commented Nov 20, 2023

Hi, kwerey!

Thank you so much for this pull request!

I've updated the Jira issue status to In Review so no one will mistakenly create a duplicate pull request. If you'd like the ability to comment on, assign, and transition issues in the future, you're welcome to create a Jira account! You can just reply here with the account name and we'll set up the permissions for you. (It makes things a bit easier for us on the organizational side if the Full Name on your Jira account either closely matches the name you'd like us to credit in the release notes or includes it in parentheses, e.g. "Nickname (PREFERRED NAME).")

Regarding the test failures, they do sound unrelated, so I've restarted them. (We try to document known failures like that on our wiki, but these sound like new ones we'll need to keep an eye on.) Usually the causes of these is test failures, where the tests run a bit too quickly in GitHub Actions and things haven't been saved, reindexed, or had their caches expired before the next step runs. In any case, there's no need to push extra commits -- someone will come along and rerun the failures in GitHub Actions.

Thanks again for contributing! If you have any questions, you can contact us at otw-coders@transformativeworks.org.

Copy link
Contributor

@Bilka2 Bilka2 left a comment

Choose a reason for hiding this comment

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

The rubocop fixes look good, thank you!

Regarding the test, it currently only tests for one of the restricted characters (<). It would be great to change it to test an array of the restricted characters, making and saving one tag per character. That way the newly added characters are tested and we will also notice if something is accidentally removed from the regex.

@kwerey kwerey force-pushed the AO3-6626/tag-characters branch from 2243127 to 0a3c354 Compare November 20, 2023 08:36
@kwerey
Copy link
Contributor Author

kwerey commented Nov 20, 2023

That makes sense! I've taken a stab at that and also tried to tidy up some of the Rubocop pings in this file - I see that Rubocop does not like just sticking an array of Forbidden Tags in the spec_helper file like we've done for forbidden emails. Figuring out some Ruby best practices is one of the things I wanna learn so very happy to go learn where constants are meant to be declared. but I won't get to that until later today.

@Bilka2
Copy link
Contributor

Bilka2 commented Nov 20, 2023

Since the bad tags are only needed in one test, they can defined directly in the test instead of in the spec_helper file. The skin spec does it that way:

[
"all",
"screen",
"handheld",
"speech",
"print",
"braille",
"embossed",
"projection",
"tty",
"tv",
"only screen and (max-width: 42em)",
"only screen and (max-width: 62em)",
"(prefers-color-scheme: dark)",
"(prefers-color-scheme: light)"
].each do |media_query|

While you're at it, please also add a tag with a backslash (\) to the array.

Copy link
Contributor

@Bilka2 Bilka2 left a comment

Choose a reason for hiding this comment

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

Looks good, thank you!

@sarken sarken merged commit a0b7645 into otwcode:master Dec 4, 2023
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants