-
Notifications
You must be signed in to change notification settings - Fork 36
ARR: Add comment preprocess for links #2976
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
Open
haroldrubio
wants to merge
10
commits into
master
Choose a base branch
from
fix/arr-comment-preprocess
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b0d39fe
Assert no links to authors
haroldrubio d326c44
Pass preprocess path
haroldrubio 0db0637
Add preprocess
haroldrubio 73deb4c
Merge branch 'master' into fix/arr-comment-preprocess
haroldrubio dcd1051
Merge branch 'master' into fix/arr-comment-preprocess
haroldrubio 8307242
Merge branch 'master' into fix/arr-comment-preprocess
haroldrubio d23f6b2
Restrict catch to just http/https
haroldrubio bba5373
Avoid regex, improve matching
haroldrubio 1b02cf3
Merge branch 'master' into fix/arr-comment-preprocess
haroldrubio 728c3df
Merge branch 'master' into fix/arr-comment-preprocess
haroldrubio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| async function process(client, edit, invitation) { | ||
| client.throwErrors = true | ||
|
|
||
| const { note } = edit | ||
| if (note.ddate) { | ||
| return | ||
| } | ||
|
|
||
| const [res1, res2] = await Promise.all([ | ||
| client.getNotes({ id: note.forum }), | ||
| client.getGroups({ id: invitation.domain }), | ||
| ]) | ||
| const forum = res1.notes[0] | ||
| const domain = res2.groups[0] | ||
| const readers = note.readers || [] | ||
| const authorsName = domain.content?.authors_name?.value || "Authors" | ||
| const authorGroupId = `${domain.id}/Submission${forum.number}/${authorsName}` | ||
| const commentText = note.content?.comment?.value || "" | ||
|
|
||
| function containsLink(text) { | ||
| const tokenChecks = [ | ||
| ["includes", ["http://", "https://", "www."]] | ||
| ] | ||
| const popularDomainSuffixes = [ | ||
| ".com", | ||
| ".net", | ||
| ".org", | ||
| ".io", | ||
| ".co", | ||
| ".tv", | ||
| ".cn", | ||
| ".de", | ||
| ".uk", | ||
| ".ru", | ||
| ".nl", | ||
| ".br" | ||
| ] | ||
| const boundaryChars = "<>()[]{}.,;:!?\"'" | ||
| let lowerText = String(text || "").toLowerCase() | ||
|
|
||
| for (const whitespace of ["\n", "\r", "\t"]) { | ||
| lowerText = lowerText.split(whitespace).join(" ") | ||
| } | ||
|
|
||
| function trimToken(token) { | ||
| let start = 0 | ||
| let end = token.length | ||
| while (start < end && boundaryChars.includes(token[start])) { | ||
| start += 1 | ||
| } | ||
| while (end > start && boundaryChars.includes(token[end - 1])) { | ||
| end -= 1 | ||
| } | ||
| return token.slice(start, end) | ||
| } | ||
|
|
||
| function matches(value, checks) { | ||
| for (const [operation, parts] of checks) { | ||
| for (const part of parts) { | ||
| if (value[operation](part)) { | ||
| return true | ||
| } | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| for (const rawToken of lowerText.split(" ")) { | ||
| const token = trimToken(rawToken) | ||
| // Skip empty tokens, emails, and tokens that cannot be hostnames. | ||
| if (!token || token.includes("@") || !token.includes(".")) { | ||
| continue | ||
| } | ||
| // Return early for explicit URL schemes and common www-style hosts. | ||
| if (matches(token, tokenChecks)) { | ||
| return true | ||
| } | ||
|
|
||
| // Trim the token to a host-like prefix before matching common web suffixes. | ||
| let host = token | ||
| for (const separator of ["/", "?", "#", ":"]) { | ||
| const index = host.indexOf(separator) | ||
| if (index !== -1) { | ||
| host = host.slice(0, index) | ||
| } | ||
| } | ||
| host = trimToken(host) | ||
|
|
||
| // Match hosts that end in one of the common web suffixes. | ||
| const firstDot = host.indexOf(".") | ||
| if (firstDot > 0 && firstDot < host.length - 1) { | ||
| for (const suffix of popularDomainSuffixes) { | ||
| if (host.endsWith(suffix)) { | ||
| return true | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| if ((readers.includes(authorGroupId) || readers.includes("everyone")) && containsLink(commentText)) { | ||
| return Promise.reject( | ||
| new OpenReviewError({ | ||
| name: "Error", | ||
| message: "Links are not allowed in official comments that are visible to authors.", | ||
| }) | ||
| ) | ||
| } | ||
|
|
||
| if (readers.includes("everyone")) { | ||
| return | ||
| } | ||
|
|
||
| const commentMandatoryReaders = | ||
| domain.content?.comment_mandatory_readers?.value || [] | ||
| for (const m of commentMandatoryReaders) { | ||
| const reader = m.replace("{number}", forum.number) | ||
| if (!readers.includes(reader)) { | ||
| return Promise.reject( | ||
| new OpenReviewError({ | ||
| name: "Error", | ||
| message: reader + " must be readers of the comment", | ||
| }) | ||
| ) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Uh oh!
There was an error while loading. Please reload this page.