Fix CourseBook term validation to accept uppercase semesters and reject partial matches

Đang mở Phù hợp với người mới
#216 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
cli

Hướng nghiên cứu

Bắt đầu từ khai báo termRegex và lệnh gọi MatchString của nó trong scrapers/coursebook.go, nơi ScrapeCoursebook kiểm tra term trước khi thiết lập. Đọc ví dụ trong README dùng -term 24F để xác nhận đầu vào mong đợi. Hoàn thành khi 24F, 24f, 26S và 26u được chấp nhận và chuẩn hóa thành chữ thường, còn 4f, 124f, 24fextra, abc24f và 24X bị từ chối với thông báo lỗi rõ ràng trước khi trình duyệt khởi động.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Description

CourseBook term validation uses the unanchored regex [0-9]{1,2}[sfu] in scrapers/coursebook.go.

This causes two problems:

  • Uppercase terms such as 24F, as documented in the README, are rejected.
  • Malformed terms such as 4f, 124f, and 24fextra pass validation because the regex accepts a matching substring.

Expected behavior:

  • Accept exactly two digits followed by S, U, or F, case-insensitively.
  • Normalize accepted terms to the lowercase format used by the CourseBook scraper before further processing.
  • Reject malformed terms with a clear error before initializing the browser or making requests.
Steps To Reproduce
  1. Build the executable with make build (or build.bat build on Windows).
  2. Run the documented command:
    ./api-tools -scrape -coursebook -term 24F
    
  3. Observe that validation rejects the uppercase semester.
  4. Inspect termRegex and its MatchString call in scrapers/coursebook.go: the pattern also accepts 4f, 124f, and 24fextra.

Malformed values that pass validation proceed toward browser initialization, so inspecting the regex is sufficient to confirm that behavior without starting a scrape.

Additional Context

Starting points:

Suggested manual checks:

  • Accept 24F, 24f, 26S, and 26u.
  • Reject 4f, 124f, 24fextra, abc24f, and 24X.
  • Confirm accepted terms reach scraper setup in the same normalized format.

Keep this task limited to term validation and normalization. Broader scraper error handling is covered by #192.

Environment

Identified by source inspection of commit 3f3585e; not reproduced by executing the scraper. The regex behavior is platform-independent.

Ngôn ngữ chính
Go
Star
12
Fork
54
Merge trung bình
14 ngày 1 giờ
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

  • Có Dockerfile hoặc tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của UTDNebula/api-tools

Tất cả issue của UTDNebula/api-tools

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.