Skip to content

Commit

Permalink
#1 검색어 필터링 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
allbegray committed Mar 30, 2023
1 parent 732d912 commit 91d62c1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}

group = 'herbaccara'
version = '0.0.3'
version = '0.0.4'
sourceCompatibility = '1.8'

publishing {
Expand Down
35 changes: 34 additions & 1 deletion src/main/kotlin/herbaccara/jusokr/JusoKrService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,39 @@ class JusoKrService(
private val objectMapper: ObjectMapper,
private val properties: JusoKrProperties
) {
companion object {

private val reservedWords = listOf(
"OR",
"SELECT",
"INSERT",
"DELETE",
"UPDATE",
"CREATE",
"DROP",
"EXEC",
"UNION",
"FETCH",
"DECLARE",
"TRUNCATE"
)

private val specialCharacters = listOf("%", "=", ">", "<")

internal fun filteredKeyword(keyword: String): String {
var filteredKeyword = keyword
for (reservedWord in JusoKrService.reservedWords) {
if (filteredKeyword.contains(reservedWord, true)) {
filteredKeyword = filteredKeyword.replace(reservedWord, "", true)
}
}
for (c in specialCharacters) {
filteredKeyword = filteredKeyword.replace(c, "")
}
return filteredKeyword.replace("\\s+".toRegex(), " ")
}
}

/***
* 검색API - 도로명주소
* https://business.juso.go.kr/addrlink/openApi/searchApi.do
Expand All @@ -28,7 +61,7 @@ class JusoKrService(
.queryParam("confmKey", properties.confmKey)
.queryParam("currentPage", currentPage)
.queryParam("countPerPage", countPerPage)
.queryParam("keyword", keyword)
.queryParam("keyword", filteredKeyword(keyword))
.queryParam("resultType", "json")
.toUriString()

Expand Down
14 changes: 14 additions & 0 deletions src/test/kotlin/herbaccara/jusokr/ReservedWordsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package herbaccara.jusokr

import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test

class ReservedWordsTest {

@Test
fun test() {
val keyword = "%=Oraa iNsErT bbiNsErT<>"
val filteredKeyword = JusoKrService.filteredKeyword(keyword)
Assertions.assertEquals("aa bb", filteredKeyword)
}
}

0 comments on commit 91d62c1

Please sign in to comment.