mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
parent
6824a0a350
commit
ae671c711d
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"oh-my-posh/environment"
|
"oh-my-posh/environment"
|
||||||
|
"oh-my-posh/regex"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
@ -82,15 +83,16 @@ func (t *Text) cleanTemplate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
knownVariable := func(variable string) bool {
|
knownVariable := func(variable string) bool {
|
||||||
if variable == "." {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
variable = strings.TrimPrefix(variable, ".")
|
variable = strings.TrimPrefix(variable, ".")
|
||||||
splitted := strings.Split(variable, ".")
|
splitted := strings.Split(variable, ".")
|
||||||
if len(splitted) == 0 {
|
if len(splitted) == 0 {
|
||||||
return false
|
return true
|
||||||
}
|
}
|
||||||
variable = splitted[0]
|
variable = splitted[0]
|
||||||
|
// check if alphanumeric
|
||||||
|
if !regex.MatchString(`^[a-zA-Z0-9]+$`, variable) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
for _, b := range knownVariables {
|
for _, b := range knownVariables {
|
||||||
if variable == b {
|
if variable == b {
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -225,6 +225,11 @@ func TestCleanTemplate(t *testing.T) {
|
||||||
Expected string
|
Expected string
|
||||||
Template string
|
Template string
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
Case: "Literal dots",
|
||||||
|
Expected: " ... ",
|
||||||
|
Template: " ... ",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Case: "Literal dot",
|
Case: "Literal dot",
|
||||||
Expected: "hello . what's up",
|
Expected: "hello . what's up",
|
||||||
|
|
Loading…
Reference in a new issue