Import LeetCode problems from a pasted link on the site
The problem list's admin row gains a link box beside "Today's LeetCode":
POST /leetcode/import takes {url} and does what `usaco new
<leetcode-link>` does, through the same lib/leetcode.py run and "Start
<slug>" commit as the daily question, then opens the solve page. A
problem already in the repo is only opened.
leetcode.Slug reads the link as slug_of in lib/leetcode.py does: full
links with /description/ and query strings, www., no scheme, or a bare
slug. Anything else is a 400.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -32,6 +32,32 @@ func TestDailyMissing(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSlug(t *testing.T) {
|
||||
for _, link := range []string{
|
||||
"https://leetcode.com/problems/two-sum/",
|
||||
"https://leetcode.com/problems/two-sum/description/?envType=daily-question",
|
||||
" https://www.leetcode.com/problems/two-sum ",
|
||||
"leetcode.com/problems/two-sum/",
|
||||
"two-sum",
|
||||
} {
|
||||
if got, err := Slug(link); err != nil || got != "two-sum" {
|
||||
t.Errorf("Slug(%q) = %q, %v; want two-sum", link, got, err)
|
||||
}
|
||||
}
|
||||
for _, link := range []string{
|
||||
"",
|
||||
"https://codeforces.com/problems/two-sum/",
|
||||
"https://leetcode.com/contest/weekly-contest-400/",
|
||||
"https://leetcode.com/problems/",
|
||||
"https://leetcode.com/problems/../x/",
|
||||
"https://evil.com/leetcode.com/problems/two-sum/",
|
||||
} {
|
||||
if got, err := Slug(link); err == nil {
|
||||
t.Errorf("Slug(%q) = %q, want an error", link, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The script's own "Error: ..." line is the message, not the exit status.
|
||||
func TestImportError(t *testing.T) {
|
||||
if _, err := exec.LookPath("python3"); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user