From ac438b62fe932f7d1ca0d6c0a4114d0ea587351b Mon Sep 17 00:00:00 2001 From: sen2y Date: Sun, 7 Jul 2024 15:30:12 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/word/word.controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/word/word.controller.js b/src/routes/word/word.controller.js index ec6d8e1..0488ade 100644 --- a/src/routes/word/word.controller.js +++ b/src/routes/word/word.controller.js @@ -13,7 +13,7 @@ exports.getSearchWords = async (req, res) => { // 검색어 검증 const validData = validateRequest(searchTermSchema, req.params); // 요청 파라미터에서 검색어 추출 - const searchTerm = validData.searchTerm; + let searchTerm = validData.searchTerm; // 검색어 조회 const data = await wordService.getSearchWords(searchTerm); if (_id) { From b0daccd82a5846a4812ab5f62e9d3c63212cb4b2 Mon Sep 17 00:00:00 2001 From: sen2y Date: Sun, 7 Jul 2024 15:32:20 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=A5=20=EC=95=88=EC=93=B0=EB=8A=94?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/word/word.repository.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/routes/word/word.repository.js b/src/routes/word/word.repository.js index 59bacdc..3eb9c00 100644 --- a/src/routes/word/word.repository.js +++ b/src/routes/word/word.repository.js @@ -3,12 +3,13 @@ const Word = require('./word.model'); exports.getSearchWords = async (searchTerm) => { try { // 대소문자 구분 없이 검색어를 찾기 위한 정규 표현식 사용 - const searchWords = await Word.findOne({ word: new RegExp(`^${searchTerm}$`, 'i') }); + const escapedSearchTerm = searchTerm.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); + const searchWords = await Word.findOne({ word: { $regex: `^${escapedSearchTerm}$`, $options: 'i' } }); if (!searchWords) { console.log('Search term not found in Word collection'); } - + console.log(888, searchWords); return searchWords; } catch (error) { console.log('Error while getting search words:', error);