unquote, trimp space
This commit is contained in:
parent
cb42e607c5
commit
4e986a823c
2 changed files with 33 additions and 1 deletions
|
@ -125,6 +125,7 @@ func ParseFile(r io.Reader) (*File, error) {
|
||||||
// pass
|
// pass
|
||||||
case stateValue:
|
case stateValue:
|
||||||
s, ok := unquote(b.String())
|
s, ok := unquote(b.String())
|
||||||
|
|
||||||
if !ok || isSpace(r) {
|
if !ok || isSpace(r) {
|
||||||
if _, err := b.WriteRune(r); err != nil {
|
if _, err := b.WriteRune(r); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -158,7 +159,13 @@ func ParseFile(r io.Reader) (*File, error) {
|
||||||
case stateComment, stateNil:
|
case stateComment, stateNil:
|
||||||
// pass; nothing to flush
|
// pass; nothing to flush
|
||||||
case stateValue:
|
case stateValue:
|
||||||
s, ok := unquote(b.String())
|
var s string
|
||||||
|
var ok bool
|
||||||
|
if cmd.Name == "model" {
|
||||||
|
s, ok = unquote(strings.TrimSpace(b.String()))
|
||||||
|
} else {
|
||||||
|
s, ok = unquote(b.String())
|
||||||
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, io.ErrUnexpectedEOF
|
return nil, io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,26 @@ func TestParseFileFrom(t *testing.T) {
|
||||||
expected []Command
|
expected []Command
|
||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
"FROM \"FOO BAR \"",
|
||||||
|
[]Command{{Name: "model", Args: "FOO BAR "}},
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"FROM \"FOO BAR\"\nPARAMETER param1 value1",
|
||||||
|
[]Command{{Name: "model", Args: "FOO BAR"}, {Name: "param1", Args: "value1"}},
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"FROM FOOO BAR ",
|
||||||
|
[]Command{{Name: "model", Args: "FOOO BAR"}},
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"FROM /what/is/the path ",
|
||||||
|
[]Command{{Name: "model", Args: "/what/is/the path"}},
|
||||||
|
nil,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"FROM foo",
|
"FROM foo",
|
||||||
[]Command{{Name: "model", Args: "foo"}},
|
[]Command{{Name: "model", Args: "foo"}},
|
||||||
|
@ -86,6 +106,11 @@ func TestParseFileFrom(t *testing.T) {
|
||||||
[]Command{{Name: "param1", Args: "value1"}, {Name: "model", Args: "foo"}},
|
[]Command{{Name: "param1", Args: "value1"}, {Name: "model", Args: "foo"}},
|
||||||
nil,
|
nil,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"PARAMETER what the \nFROM lemons make lemonade ",
|
||||||
|
[]Command{{Name: "what", Args: "the "}, {Name: "model", Args: "lemons make lemonade"}},
|
||||||
|
nil,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
|
|
Loading…
Add table
Reference in a new issue