aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--content.go7
-rw-r--r--formspec.go10
2 files changed, 9 insertions, 8 deletions
diff --git a/content.go b/content.go
index 849691f..6712067 100644
--- a/content.go
+++ b/content.go
@@ -17,6 +17,8 @@ import (
//go:generate go run gen_textures.go
+var disallowedChars = regexp.MustCompile("[^a-zA-Z0-9-_.:]")
+
var b64 = base64.StdEncoding
type mediaFile struct {
@@ -502,9 +504,8 @@ func isDefaultNode(s string) bool {
func prependRaw(prep string, s *string, isTexture bool) {
if !isDefaultNode(*s) {
- reg := regexp.MustCompile("[^a-zA-Z0-9-_.:]")
- subs := reg.Split(*s, -1)
- seps := reg.FindAllString(*s, -1)
+ subs := disallowedChars.Split(*s, -1)
+ seps := disallowedChars.FindAllString(*s, -1)
for i, sub := range subs {
if !isTexture || strings.Contains(sub, ".") {
diff --git a/formspec.go b/formspec.go
index 12553f1..a8a1ea2 100644
--- a/formspec.go
+++ b/formspec.go
@@ -5,14 +5,14 @@ import (
"strings"
)
+var textureName = regexp.MustCompile("[a-zA-Z0-9-_.]*\\.[a-zA-Z-_.]+")
+
func (sc *ServerConn) prependFormspec(fs *string) {
- reg := regexp.MustCompile("[^a-zA-Z0-9-_.:]")
- reg2 := regexp.MustCompile("[a-zA-Z0-9-_.]*\\.[a-zA-Z-_.]+")
- subs := reg.Split(*fs, -1)
- seps := reg.FindAllString(*fs, -1)
+ subs := disallowedChars.Split(*fs, -1)
+ seps := disallowedChars.FindAllString(*fs, -1)
for i, sub := range subs {
- if reg2.MatchString(sub) && !strings.Contains(sub, " ") {
+ if textureName.MatchString(sub) && !strings.Contains(sub, " ") {
prepend(sc.name, &subs[i])
}
}