Feat(#6): 대화 텍스트 내 URL 정규식 추출 기능 구현 - #8
Conversation
📝 WalkthroughWalkthroughAdds a voice-phishing analysis endpoint, updates the SMS analysis response message and annotations, and introduces a tested utility for extracting, cleaning, ordering, and deduplicating URLs from text. ChangesAnalysis features
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/test_url_extractor.py (1)
23-27: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winExpand punctuation tests to cover the documented behavior.
This test only verifies a trailing period, so regressions involving commas, closing brackets, or valid URLs ending in balanced parentheses would pass unnoticed.
🧪 Proposed test expansion
def test_url_with_trailing_punctuation(self): """시나리오 4: 문장 맨 끝에 온점이나 기호와 함께 URL이 위치한 경우 -> 기호 제외하고 깔끔하게 추출 (억까 방지)""" - text = "아래 단축 링크를 꼭 클릭해주세요: https://bit.ly/3xyz." - expected = ["https://bit.ly/3xyz"] - self.assertEqual(extract_urls_from_text(text), expected) + cases = [ + ("링크: https://example.com/path,", ["https://example.com/path"]), + ("링크: (https://example.com/path).", ["https://example.com/path"]), + ( + "링크: https://en.wikipedia.org/wiki/Foo_(bar)", + ["https://en.wikipedia.org/wiki/Foo_(bar)"], + ), + ] + for text, expected in cases: + with self.subTest(text=text): + self.assertEqual(extract_urls_from_text(text), expected)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/test_url_extractor.py` around lines 23 - 27, Expand test_url_with_trailing_punctuation to cover trailing commas and closing brackets, plus a valid URL whose path ends with balanced parentheses. Assert punctuation is excluded while balanced parentheses remain part of the extracted URL, preserving the documented extraction behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/service/url/url_extractor.py`:
- Around line 20-22: Update the URL-cleaning loop in the URL extraction function
to trim sentence punctuation only when it is clearly attached, preserving valid
trailing URL characters. Remove closing brackets such as “)” or “]” only when
they are unmatched by corresponding opening brackets in the URL, so balanced URL
paths like “Foo_(bar)” remain intact.
---
Nitpick comments:
In `@tests/test_url_extractor.py`:
- Around line 23-27: Expand test_url_with_trailing_punctuation to cover trailing
commas and closing brackets, plus a valid URL whose path ends with balanced
parentheses. Assert punctuation is excluded while balanced parentheses remain
part of the extracted URL, preserving the documented extraction behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 676982c2-b3b5-46b4-9dca-de2d6f4c05cc
📒 Files selected for processing (4)
app/router/analyze.pyapp/router/analyze_voice.pyapp/service/url/url_extractor.pytests/test_url_extractor.py
| for url in raw_urls: | ||
| cleaned_url = url.rstrip('.,?!:;)[]') | ||
| cleaned_urls.append(cleaned_url) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Preserve valid URL punctuation when trimming sentence punctuation.
rstrip('.,?!:;)[]') blindly removes valid trailing URL characters. For example, https://en.wikipedia.org/wiki/Foo_(bar) becomes https://en.wikipedia.org/wiki/Foo_(bar, which can make downstream URL analysis miss the original URL. Trim sentence punctuation only when it is clearly attached, and remove closing brackets only when they are unmatched.
🐛 Proposed fix
for url in raw_urls:
- cleaned_url = url.rstrip('.,?!:;)[]')
+ cleaned_url = url.rstrip(".,?!:;")
+ if cleaned_url.endswith(")") and cleaned_url.count(")") > cleaned_url.count("("):
+ cleaned_url = cleaned_url[:-1]
+ if cleaned_url.endswith("]") and cleaned_url.count("]") > cleaned_url.count("["):
+ cleaned_url = cleaned_url[:-1]
cleaned_urls.append(cleaned_url)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| for url in raw_urls: | |
| cleaned_url = url.rstrip('.,?!:;)[]') | |
| cleaned_urls.append(cleaned_url) | |
| for url in raw_urls: | |
| cleaned_url = url.rstrip(".,?!:;") | |
| if cleaned_url.endswith(")") and cleaned_url.count(")") > cleaned_url.count("("): | |
| cleaned_url = cleaned_url[:-1] | |
| if cleaned_url.endswith("]") and cleaned_url.count("]") > cleaned_url.count("["): | |
| cleaned_url = cleaned_url[:-1] | |
| cleaned_urls.append(cleaned_url) |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@app/service/url/url_extractor.py` around lines 20 - 22, Update the
URL-cleaning loop in the URL extraction function to trim sentence punctuation
only when it is clearly attached, preserving valid trailing URL characters.
Remove closing brackets such as “)” or “]” only when they are unmatched by
corresponding opening brackets in the URL, so balanced URL paths like
“Foo_(bar)” remain intact.
📝 개요
사용자가 입력한 텍스트 내에서 악성 피싱 URL을 판별하기 위한 전처리 파이프라인의 1단계인 **'URL 정규식 추출 기능'**을 구현했습니다.
메인 백엔드(Spring) 서버와의 원할한 인터페이스 연동 및 통합 테스트를 위해 음성 분석용 더미 엔드포인트를 미리 확보했습니다.
🔗 관련 이슈
🎯 주요 변경 사항
정규식 기반의 URL 추출기 구현
http://또는https://로 시작하는 웹 주소를 매칭하는 정규표현식 파이프라인 구현.), 쉼표(,), 괄호(]) 등의 문장부호가 URL 문자열에 포함되어 도메인이 깨지는 억까 케이스 방어 로직 적용5개 시나리오 기반 단위 테스트 검증 완
보이스피싱 탐지용 음성 분석 라우터 초안 확보
📸 사진
✅ PR 체크리스트
uvicorn구동 또는 테스트 코드)를 통과했습니다.Summary by CodeRabbit
New Features
Improvements
Tests