Commit 8db91fe2 authored by Kyle Clarke's avatar Kyle Clarke

Removal of whitespace stripping

This opens up the package to be used with more scope via the caller.
It's the caller responsibility to define the expected prefix, spaces n
all to match against the payload.
parent 60565b75
Pipeline #20083978 passed with stage
......@@ -47,11 +47,9 @@ func WhatJSON(b []byte, prefix ...string) (JSONType, error) {
// If we do not have a matched prefix, check the byte value and add to the buffer.
if !prefixMatch {
if c != ' ' && c != '\t' && c != '\r' && c != '\n' {
err := matchBuf.WriteByte(c)
if err == nil && matchBuf.String() == pfx {
prefixMatch = true
}
err := matchBuf.WriteByte(c)
if err == nil && matchBuf.String() == pfx {
prefixMatch = true
}
continue
......
......@@ -7,7 +7,7 @@ import (
)
func TestWhatJSONArray(t *testing.T) {
body := []byte(" { data:{[[{")
body := []byte("{data:{[[{")
rt, err := WhatJSON(body, "{data:{")
if err != nil {
t.Error(err)
......@@ -17,7 +17,7 @@ func TestWhatJSONArray(t *testing.T) {
}
// Check prefix with spaces expecting array
rt, err = WhatJSON(body, " { d at a: {")
rt, err = WhatJSON(body, "{data:{")
if err != nil {
t.Error(err)
}
......@@ -27,7 +27,7 @@ func TestWhatJSONArray(t *testing.T) {
}
func TestWhatJSONNoPrefix(t *testing.T) {
body := []byte(" { data:{[[{")
body := []byte(" {data:{[[{")
rt, err := WhatJSON(body)
if err != nil {
t.Error(err)
......@@ -50,7 +50,7 @@ func TestWhatJSONBadPrefix(t *testing.T) {
}
func TestWhatJSONDeepNesting(t *testing.T) {
body := []byte(" { data:{[[{")
body := []byte("{data:{[[{")
rt, err := WhatJSON(body, "{data:{[")
if err != nil {
......@@ -101,7 +101,7 @@ func TestWhatJSONNonJSONBody(t *testing.T) {
func TestWhatJSONObject(t *testing.T) {
// Assert empty prefix.
body := []byte(" { data:{[[{")
body := []byte("{data:{[[{")
rt, err := WhatJSON(body, "")
if err != nil {
t.Error(err)
......@@ -130,7 +130,7 @@ func TestWhatJSONObject(t *testing.T) {
}
func TestWhatJSONUnknown(t *testing.T) {
body := []byte(" { data:{[[{")
body := []byte("{data:{[[{")
rt, err := WhatJSON(body, "{")
if err != nil {
t.Error(err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment