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 Website Breakage Reports by allowing unescaped commas in URL query #498

Merged
merged 4 commits into from
Apr 4, 2022

Conversation

ayoy
Copy link
Collaborator

@ayoy ayoy commented Apr 1, 2022

Task/Issue URL: https://app.asana.com/0/1163321984198618/1202033667108435/f
Tech Design URL:
CC:

Description:
Website Breakage reporting uses comma (a reserved character as described by RFC 3986) to separate blocked trackers domains in a single URL query parameter. Since we upgraded URL.addParameter to percent-encode all reserved characters, macOS website breakage reports got malformed, because of percent-encoded commas.
This change utilizes an update to URL.addParameter (added in BSK) that allows to explicitly specify characters that are excluded from percent encoding. Then, in WebsiteBreakageSender, a comma is added as allowed character, to fix the reports.
Adding this new API required updating APIRequest and Pixel's code, but since the allowed characters set defaults to nil and is an opt-in feature, no API request other than Website Breakage should change.

I also added the initial version of Website Breakage reference tests, which checks contents of URL requests sent via Pixel. Here is the reference JSON file I was inspired by. Since it turned out that our breakage reporting mechanism is a little bit off relative to the reference, I made the following changes:

  • removed query and fragment from website URLs
  • added the gpc flag
  • parametrized the manufacturer - it defaults to "Apple" anyway, but reference tests JSON contains different values there so I enabled it for the future when we'll have automatic tests working on the JSON file.

Steps to test this PR:

  1. Make sure all tests pass
  2. Make sure semicolons in search queries work as intended (i.e. are percent-encoded)
  3. Make sure feedback is not truncated at the semicolon
  4. Verify that all other network connectivity (that I'm not aware of yet) besides web browsing is intact

Testing checklist:

  • Test with Release configuration
  • Test proper deallocation of tabs
  • Make sure committed submodule changes are desired

Internal references:

Software Engineering Expectations
Technical Design Template
When ready for review, remember to post the PR in MM

Copy link
Contributor

@tomasstrba tomasstrba left a comment

Choose a reason for hiding this comment

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

LGMT! 👍 💯 Special shout-out for unit test coverage! 👏

I only have few optional suggestions and ignore my self talk about empty characters 😆

)
}

func parameters(from websiteBreakage: WebsiteBreakage) -> [String: String] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: This method could be private (Helps readers with the separation of class API and class internal logic)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The reason why this method remained public is that it's used in unit tests. But it actually has no dependency on WebsiteBreakageSender, so I'll refactor it into a computed property on WebsiteBreakage called requestParameters. It should make things more clear.

DuckDuckGo/API/APIRequest.swift Show resolved Hide resolved
urlParametersRemoved: Bool,
manufacturer: String = "Apple"
) {
var siteUrlComponents = URLComponents(string: siteUrlString)
Copy link
Contributor

Choose a reason for hiding this comment

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

The breakage form has a URL field which shows what URL are we going to submit. The trimming of query and fragment is in the layer above - in the view controller layer. I don't recommend doing the trimming on two places in case something changes. I you want to be sure things are trimmed, this can be just an assertion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're obviously right, I missed that part of code. Will remove it.

}

static let allowedQueryReservedCharacters = CharacterSet(charactersIn: ",")
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: It is a good practice to have static variables or methods on top

@tomasstrba tomasstrba assigned ayoy and unassigned tomasstrba Apr 4, 2022
@ayoy ayoy removed the don’t merge label Apr 4, 2022
@ayoy ayoy merged commit 49b8934 into develop Apr 4, 2022
@ayoy ayoy deleted the dominik/site-breakage-report branch April 4, 2022 12:57
samsymons added a commit that referenced this pull request Apr 10, 2022
# By Dominik Kapusta (2) and Tomas Strba (1)
# Via Tomas Strba
* develop:
  Version 0.22.0
  Fix Website Breakage Reports by allowing unescaped commas in URL query (#498)
  Fix LoginsPreferences instances being out of sync (#499)

# Conflicts:
#	DuckDuckGo.xcodeproj/project.pbxproj
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.

2 participants