Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions phpcfg/phpcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ func getReturnedArray(ret *stmt.Return) node.Node {
return nil
}

// Removes single quotes if present.
// Removes surrounding quotes (single or double) if present.
func unquote(s string) string {
if s[0] == '\'' && s[len(s)-1] == '\'' {
if len(s) >= 2 && (s[0] == '\'' || s[0] == '"') && s[len(s)-1] == s[0] {
return s[1 : len(s)-1]
}
return s
Expand Down
37 changes: 37 additions & 0 deletions phpcfg/phpcfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,43 @@ return [
}
}

func TestParseDoubleQuotedStrings(t *testing.T) {
src := `
<?php
return [
"db" => [
"table_prefix" => "",
"connection" => [
"default" => [
"host" => "localhost",
"dbname" => "somename123_db",
"password" => "aabbccddeeff",
"active" => "1",
"driver_options" => [
1014 => FALSE
]
]
]
]
];`

expected := map[string]string{
"root.db.table_prefix": "",
"root.db.connection.default.host": "localhost",
"root.db.connection.default.dbname": "somename123_db",
"root.db.connection.default.password": "aabbccddeeff",
"root.db.connection.default.active": "1",
"root.db.connection.default.driver_options.1014": "FALSE",
}

parsed, err := Parse([]byte(src))
if err != nil {
t.Error("Parse failed:", err)
} else if !cmp.Equal(parsed, expected) {
t.Error("Parsed != expected:", cmp.Diff(expected, parsed))
}
}

func TestParseArray(t *testing.T) {
src := `
<?php
Expand Down
Loading