Skip to content

Commit

Permalink
SCHP-126 Fix emoji comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerviba committed Mar 6, 2022
1 parent 7a29f3c commit a6df27f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package hu.kirdev.schpincer.service

import hu.kirdev.schpincer.dao.OrderRepository
import hu.kirdev.schpincer.model.*
import hu.kirdev.schpincer.web.removeNonPrintable

class ChangeOrderProcedure(
private val user: UserEntity,
Expand Down Expand Up @@ -43,7 +44,7 @@ class ChangeOrderProcedure(

private fun updateDetails() {
order.room = room
order.comment = "[${user.cardType.name}] $comment"
order.comment = "[${user.cardType.name}] ${comment.removeNonPrintable()}"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import hu.kirdev.schpincer.dto.ManualUserDetails
import hu.kirdev.schpincer.dto.OrderDetailsDto
import hu.kirdev.schpincer.model.*
import hu.kirdev.schpincer.web.component.*
import hu.kirdev.schpincer.web.removeNonPrintable
import java.util.*

class FailedOrderException(val response: String) : RuntimeException()
Expand Down Expand Up @@ -46,7 +47,7 @@ class MakeOrderProcedure (
order = OrderEntity(
userId = manualUser.id,
userName = manualUser.name,
comment = "[${manualUser.card}] @ ${user.name} | $comment",
comment = "[${manualUser.card}] @ ${user.name} | ${comment.removeNonPrintable()}",
detailsJson = detailsJson,
room = manualUser.room,
createdAt = System.currentTimeMillis())
Expand Down
13 changes: 11 additions & 2 deletions src/main/kotlin/hu/kirdev/schpincer/web/Utility.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ fun toReadableRole(permissions: Set<String>, circleID: Long): CircleMemberRole {
val dateFormat: DateFormat by lazy { SimpleDateFormat("yyyy-MM-dd hh:mm") }

fun parseDate(dateToParse: String): Long {
val date: Date
date = try {
val date: Date = try {
dateFormat.parse(dateToParse)
} catch (e: ParseException) {
e.printStackTrace()
Expand All @@ -115,3 +114,13 @@ fun formatDate(date: Long): String {
fun HttpServletRequest.isInInternalNetwork(): Boolean {
return this.remoteAddr.startsWith("152.66.") || this.remoteAddr == "127.0.0.1"
}

val nonAscii = Regex("[^\\x00-\\u0170]")
val controlChars = Regex("[\\p{Cntrl}&&[^\r\n\t]]")
val nonPrintable = Regex("\\p{C}")

fun String.removeNonPrintable() =
this.replace(nonAscii, "")
.replace(controlChars, "")
.replace(nonPrintable, "")
.trim()
6 changes: 4 additions & 2 deletions src/main/resources/templates/fragments/itemPopup.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ <h5 id="popup-price-tag" th:text="#{lang.items.price}">ÁR</h5>
<option value="3">19:30 - 20:00 (20 db)</option>
</select>
<label th:text="#{lang.items.comment}">Comment</label>
<input id="popup-comment" type="text" name="comment" autocomplete="off" maxlength="200"/>
<input id="popup-comment" type="text" name="comment" autocomplete="off" maxlength="200"
onchange="this.value = this.value.replaceAll(/[^\x00-\u0170]/, '')"
onkeyup="this.value = this.value.replaceAll(/[^\x00-\u0170]/, '')"/>
<input type="submit" id="submit-order-button" class="colored-light submit-button" value="Order"
th:value="#{lang.items.buy}" th:unless="${session.user} eq null"/>
</div>
Expand All @@ -79,4 +81,4 @@ <h5 id="popup-price-tag" th:text="#{lang.items.price}">ÁR</h5>
</div>
</div>
</body>
</html>
</html>
4 changes: 3 additions & 1 deletion src/main/resources/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ <h4 th:text="${session.user?.name}" class="user">User Name</h4>
<form id="room-form" style="display: none" onsubmit="setRoom(); return false" action="#"
method="GET">
<input type="text" id="room-setter" maxlength="8" autocomplete="off"
onfocusout="setRoom(); return false"/>
onfocusout="setRoom(); return false"
onchange="this.value = this.value.replaceAll(/[^A-Za-z0-9 -_()]/, '')"
onkeyup="this.value = this.value.replaceAll(/[^A-Za-z0-9 -_()]/, '')" />
<ins id="saved" th:text="#{lang.profile.room-number-hint}">(Szám vagy terem neve)</ins>
</form>
<ins id="saved" th:text="#{lang.profile.saved}">Elmentve</ins>
Expand Down

0 comments on commit a6df27f

Please sign in to comment.