From d4dca8626716768afa1e6b8db46bb9e70da7f828 Mon Sep 17 00:00:00 2001 From: Vikram Rangnekar Date: Tue, 14 Jan 2020 23:16:55 -0500 Subject: [PATCH] Fix new app creation bug #32 --- jsn/filter.go | 4 ++-- jsn/get.go | 4 ++-- jsn/json_test.go | 8 ++++---- jsn/keys.go | 4 ++-- jsn/replace.go | 4 ++-- jsn/strip.go | 4 ++-- serv/args.go | 7 +++++++ serv/cmd_new.go | 4 ++-- 8 files changed, 23 insertions(+), 16 deletions(-) diff --git a/jsn/filter.go b/jsn/filter.go index c8d95de..582726e 100644 --- a/jsn/filter.go +++ b/jsn/filter.go @@ -64,7 +64,7 @@ func Filter(w *bytes.Buffer, b []byte, keys []string) error { state = expectKeyClose s = i - case state == expectKeyClose && b[i] == '"': + case state == expectKeyClose && (b[i-1] != '\\' && b[i] == '"'): state = expectColon k = b[(s + 1):i] @@ -74,7 +74,7 @@ func Filter(w *bytes.Buffer, b []byte, keys []string) error { case state == expectValue && b[i] == '"': state = expectString - case state == expectString && b[i] == '"': + case state == expectString && (b[i-1] != '\\' && b[i] == '"'): e = i case state == expectValue && b[i] == '[': diff --git a/jsn/get.go b/jsn/get.go index 86ba3b5..dff265b 100644 --- a/jsn/get.go +++ b/jsn/get.go @@ -66,7 +66,7 @@ func Get(b []byte, keys [][]byte) []Field { state = expectKeyClose s = i - case state == expectKeyClose && b[i] == '"': + case state == expectKeyClose && (b[i-1] != '\\' && b[i] == '"'): state = expectColon k = b[(s + 1):i] @@ -77,7 +77,7 @@ func Get(b []byte, keys [][]byte) []Field { state = expectString s = i - case state == expectString && b[i] == '"': + case state == expectString && (b[i-1] != '\\' && b[i] == '"'): e = i case state == expectValue && b[i] == '[': diff --git a/jsn/json_test.go b/jsn/json_test.go index 9760396..66aae7f 100644 --- a/jsn/json_test.go +++ b/jsn/json_test.go @@ -13,12 +13,12 @@ var ( "users": [ { "id": 1, - "full_name": "Sidney Stroman", + "full_name": "'Sidney Stroman'", "email": "user0@demo.com", "__twitter_id": "2048666903444506956", "embed": { "id": 8, - "full_name": "Caroll Orn Sr.", + "full_name": "Caroll Orn Sr's", "email": "joannarau@hegmann.io", "__twitter_id": "ABC123" "more": [{ @@ -37,7 +37,7 @@ var ( "id": 3, "full_name": "Kenna Cassin", "email": "user2@demo.com", - "__twitter_id": { "name": "hello", "address": { "work": "1 infinity loop" } } + "__twitter_id": { "name": "\"hellos\"", "address": { "work": "1 infinity loop" } } }, { "id": 4, @@ -171,7 +171,7 @@ func TestGet(t *testing.T) { {[]byte("__twitter_id"), []byte(`[{ "name": "hello" }, { "name": "world"}]`)}, {[]byte("__twitter_id"), - []byte(`{ "name": "hello", "address": { "work": "1 infinity loop" } }`), + []byte(`{ "name": "\"hellos\"", "address": { "work": "1 infinity loop" } }`), }, {[]byte("__twitter_id"), []byte(`1234567890`)}, {[]byte("__twitter_id"), []byte(`1.23E`)}, diff --git a/jsn/keys.go b/jsn/keys.go index 0ebf69f..06ba0ad 100644 --- a/jsn/keys.go +++ b/jsn/keys.go @@ -47,7 +47,7 @@ func Keys(b []byte) [][]byte { state = expectKeyClose s = i - case state == expectKeyClose && b[i] == '"': + case state == expectKeyClose && (b[i-1] != '\\' && b[i] == '"'): state = expectColon k = b[(s + 1):i] @@ -58,7 +58,7 @@ func Keys(b []byte) [][]byte { state = expectString s = i - case state == expectString && b[i] == '"': + case state == expectString && (b[i-1] != '\\' && b[i] == '"'): e = i case state == expectValue && b[i] == '{': diff --git a/jsn/replace.go b/jsn/replace.go index 196590d..44eddc4 100644 --- a/jsn/replace.go +++ b/jsn/replace.go @@ -52,7 +52,7 @@ func Replace(w *bytes.Buffer, b []byte, from, to []Field) error { state = expectKeyClose s = i - case state == expectKeyClose && b[i] == '"': + case state == expectKeyClose && (b[i-1] != '\\' && b[i] == '"'): state = expectColon if _, err := h.Write(b[(s + 1):i]); err != nil { return err @@ -66,7 +66,7 @@ func Replace(w *bytes.Buffer, b []byte, from, to []Field) error { state = expectString s = i - case state == expectString && b[i] == '"': + case state == expectString && (b[i-1] != '\\' && b[i] == '"'): e = i case state == expectValue && b[i] == '[': diff --git a/jsn/strip.go b/jsn/strip.go index e6dc64e..827cdf7 100644 --- a/jsn/strip.go +++ b/jsn/strip.go @@ -27,7 +27,7 @@ func Strip(b []byte, path [][]byte) []byte { state = expectKeyClose s = i - case state == expectKeyClose && b[i] == '"': + case state == expectKeyClose && (b[i-1] != '\\' && b[i] == '"'): state = expectColon if pi == len(path) { pi = 0 @@ -44,7 +44,7 @@ func Strip(b []byte, path [][]byte) []byte { state = expectString s = i - case state == expectString && b[i] == '"': + case state == expectString && (b[i-1] != '\\' && b[i] == '"'): e = i case state == expectValue && b[i] == '[': diff --git a/serv/args.go b/serv/args.go index 048f27b..27a0a06 100644 --- a/serv/args.go +++ b/serv/args.go @@ -33,7 +33,12 @@ func argMap(ctx context.Context, vars []byte) func(w io.Writer, tag string) (int return 0, errors.New("query requires variable $user_role") } + fmt.Println("1>", tag) + fmt.Println("2>", string(vars)) + fields := jsn.Get(vars, [][]byte{[]byte(tag)}) + fmt.Println("2.1>", fields) + if len(fields) == 0 { return 0, nil } @@ -42,6 +47,8 @@ func argMap(ctx context.Context, vars []byte) func(w io.Writer, tag string) (int fields[0].Value = v[1 : len(v)-1] } + fmt.Println("3>", string(fields[0].Value)) + return w.Write(escQuote(fields[0].Value)) } } diff --git a/serv/cmd_new.go b/serv/cmd_new.go index 1a649ae..b2be52b 100644 --- a/serv/cmd_new.go +++ b/serv/cmd_new.go @@ -90,8 +90,8 @@ func cmdNew(cmd *cobra.Command, args []string) { return os.Mkdir(p, os.ModePerm) }) - ifNotExists(path.Join(appMigrationsPath, "100_init.sql"), func(p string) error { - if v, err := tmpl.get("100_init.sql"); err == nil { + ifNotExists(path.Join(appMigrationsPath, "0_init.sql"), func(p string) error { + if v, err := tmpl.get("0_init.sql"); err == nil { return ioutil.WriteFile(p, v, 0644) } else { return err