Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/src/main/scala/codesearch/core/util/RegexTester.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package codesearch.core.util

import scala.util.matching.Regex

object RegexTester {

def regexIsInvalid(regex: String, line: String): Boolean = {
try {
regex.r.findAllMatchIn(line)
false
} catch {
case x: java.util.regex.PatternSyntaxException => true
}
}

}
23 changes: 20 additions & 3 deletions web-server/app/views/resultFrame.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,38 @@
@import codesearch.web.SnippetHelper

@import java.net.URLEncoder
@import codesearch.core.util.RegexTester
@(
lang: String,
insensitive: Boolean,
space: Boolean,
precise: Boolean,
query: String,
updated: String,
packages: Seq[PackageResult],
totalMatches: Int
totalMatches: Int,
precise: Boolean,
sources: Boolean,
withoutTests: Boolean,
)

@regex = @{
RegexConstructor(query = query, space = space, insensitive = insensitive, precise = precise)
}

@if(RegexTester.regexIsInvalid(regex, "line")) {
<script>
if (!document.getElementsByClassName('error')[0].classList.contains('show')) {
document.getElementsByClassName('error')[0].classList.add('show')
inpQuery.classList.add('error')
}
</script>
}
@if(!RegexTester.regexIsInvalid(regex, "line")) {
<script>
document.getElementsByClassName('error')[0].classList.remove('show')
inpQuery.classList.remove('error')
</script>
}
<section class="container">
<span class="text-secondary">Index updated @updated</span> <br>

Expand Down Expand Up @@ -71,4 +88,4 @@ <h4 class="display-7" style="margin-bottom: 0em; margin-top: 2em; text-align: le
</pre>
}
}
</section>
</section>
2 changes: 2 additions & 0 deletions web-server/app/views/searchBox.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
precise: Boolean,
sources: Boolean,
withoutTests: Boolean,
invalidRegex: Boolean = false
)

<section class="container-fluid">
<div class="col-lg-6 mx-auto p-3 h7 justify-content-center" style="position: relative;">
<form>
<section class="warning warning-query">Please provide a string to search for.</section>
<section class="error warning-query">You entered wrong regexp.</section>
<div class="input-group mb-2">
<input type="text" class="form-control" name="query" value="@query" class="query">
<div class="input-group-append">
Expand Down
2 changes: 1 addition & 1 deletion web-server/app/views/searchResults.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@

@wrapper(s"Codesearch | $lang", headExtra) {
@searchBox(s"/$lang/search", query, filter, filePath, insensitive, space, precise, sources, withoutTests)
@resultFrame(lang, insensitive, space, precise, query, updated, packages, totalMatches)
@resultFrame(lang, insensitive, space, query, updated, packages, totalMatches, precise, sources, withoutTests)
@pagination(page, totalMatches, callURI)
}