mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-25 18:07:07 +09:00
Merge pull request #4044 from JoeKar/fix/crash-glob
Fix crash with file globbing matching micro option names
This commit is contained in:
@@ -186,11 +186,19 @@ func validateParsedSettings() error {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if _, e := glob.Compile(k); e != nil {
|
||||
err = errors.New("Error with glob setting " + k + ": " + e.Error())
|
||||
tk := strings.TrimPrefix(k, "glob:")
|
||||
if _, e := glob.Compile(tk); e != nil {
|
||||
err = errors.New("Error with glob setting " + tk + ": " + e.Error())
|
||||
delete(parsedSettings, k)
|
||||
continue
|
||||
}
|
||||
if !strings.HasPrefix(k, "glob:") {
|
||||
// Support non-prefixed glob settings but internally convert
|
||||
// them to prefixed ones for simplicity.
|
||||
delete(parsedSettings, k)
|
||||
k = "glob:" + k
|
||||
parsedSettings[k] = v
|
||||
}
|
||||
for k1, v1 := range v.(map[string]any) {
|
||||
if _, ok := defaults[k1]; ok {
|
||||
if e := verifySetting(k1, v1, defaults[k1]); e != nil {
|
||||
@@ -256,6 +264,9 @@ func ReadSettings() error {
|
||||
func ParsedSettings() map[string]any {
|
||||
s := make(map[string]any)
|
||||
for k, v := range parsedSettings {
|
||||
if strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
|
||||
continue
|
||||
}
|
||||
s[k] = v
|
||||
}
|
||||
return s
|
||||
@@ -309,8 +320,9 @@ func InitGlobalSettings() error {
|
||||
// Must be called after ReadSettings
|
||||
func UpdatePathGlobLocals(settings map[string]any, path string) {
|
||||
for k, v := range parsedSettings {
|
||||
if strings.HasPrefix(reflect.TypeOf(v).String(), "map") && !strings.HasPrefix(k, "ft:") {
|
||||
g, _ := glob.Compile(k)
|
||||
if strings.HasPrefix(reflect.TypeOf(v).String(), "map") && strings.HasPrefix(k, "glob:") {
|
||||
tk := strings.TrimPrefix(k, "glob:")
|
||||
g, _ := glob.Compile(tk)
|
||||
if g.MatchString(path) {
|
||||
for k1, v1 := range v.(map[string]any) {
|
||||
settings[k1] = v1
|
||||
|
||||
@@ -669,6 +669,21 @@ all files except Go files, and `tabsize` 4 for all files except Ruby files:
|
||||
|
||||
Or similarly you can match with globs:
|
||||
|
||||
```json
|
||||
{
|
||||
"glob:*.go": {
|
||||
"tabstospaces": false
|
||||
},
|
||||
"glob:*.rb": {
|
||||
"tabsize": 2
|
||||
},
|
||||
"tabstospaces": true,
|
||||
"tabsize": 4
|
||||
}
|
||||
```
|
||||
|
||||
You can also omit the `glob:` prefix before globs:
|
||||
|
||||
```json
|
||||
{
|
||||
"*.go": {
|
||||
@@ -681,3 +696,6 @@ Or similarly you can match with globs:
|
||||
"tabsize": 4
|
||||
}
|
||||
```
|
||||
|
||||
But it is generally more recommended to use the `glob:` prefix, as it avoids
|
||||
potential conflicts with option names.
|
||||
|
||||
Reference in New Issue
Block a user