-
Notifications
You must be signed in to change notification settings - Fork 0
Sanitize document titles + drop repeated icon-glyph marker rows #56
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
Merged
+123
−3
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,20 @@ | ||
| package handler | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestSanitizeTitle(t *testing.T) { | ||
| cases := []struct{ in, want string }{ | ||
| {"Attention Is All You Need", "Attention Is All You Need"}, | ||
| {" spaced out title ", "spaced out title"}, | ||
| {"Berkshire — 2023", "Berkshire — 2023"}, // valid UTF-8 em-dash is kept | ||
| {"bad\xff\xfebyte", "badbyte"}, // invalid UTF-8 bytes dropped | ||
| {"line\nbreak\ttab", "line break tab"}, // control chars → space, collapsed | ||
| {"\xff\xfe", ""}, // all-garbage collapses to empty | ||
| {"", ""}, | ||
| } | ||
| for _, c := range cases { | ||
| if got := sanitizeTitle(c.in); got != c.want { | ||
| t.Errorf("sanitizeTitle(%q) = %q, want %q", c.in, got, c.want) | ||
| } | ||
| } | ||
| } |
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
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,32 @@ | ||
| package parser | ||
|
|
||
| import "testing" | ||
|
|
||
| // TestIsRepeatedMarkerLine locks the filter that drops icon-glyph marker | ||
| // rows (e.g. an ORCID "iD" repeated once per author) while never touching | ||
| // real prose or short headings. | ||
| func TestIsRepeatedMarkerLine(t *testing.T) { | ||
| drop := []string{ | ||
| "id id id id", // 4/4 = 100% | ||
| "iD iD iD iD", // case-insensitive caller lower-cases first; test raw too | ||
| "id id id", // 3/3 | ||
| "id id id id author", // 4/5 = 80% ≥ 60% | ||
| } | ||
| keep := []string{ | ||
| "the right to erasure is established in article 17", | ||
| "multi-head attention", // 2 tokens, below the 3-token floor | ||
| "introduction", // single token | ||
| "id id id penny whiting17, david moher 22", // 3 of 9 ≈ 33% → real author line, kept | ||
| "id id elie a. akl 8, sue e. brennan", // 2 of 8 → kept | ||
| } | ||
| for _, s := range drop { | ||
| if !isRepeatedMarkerLine(s) { | ||
| t.Errorf("expected DROP for %q", s) | ||
| } | ||
| } | ||
| for _, s := range keep { | ||
| if isRepeatedMarkerLine(s) { | ||
| t.Errorf("expected KEEP for %q", s) | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
RuneError check drops legitimate U+FFFD characters.
utf8.RuneErrorand'\uFFFD'are the same value. Sinceswas already coerced viastrings.ToValidUTF8(s, "")above,for _, r := range scan no longer decode an actual invalid byte toRuneErrorhere — anyr == utf8.RuneErrorat this point is a legitimately-encoded "�" character in the input, not a decode failure. The current check silently strips these valid characters instead of a decode error.🐛 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents