Skip to content
This repository has been archived by the owner on Mar 31, 2019. It is now read-only.

StartAtValue or EndAtValue with string starting with "+" plus symbol #89

Closed
arturscheiner opened this issue Oct 9, 2017 · 7 comments
Closed
Labels

Comments

@arturscheiner
Copy link

arturscheiner commented Oct 9, 2017

Figured out that these methods StartAtValue and EndAtValue, returns a empty map[] if the string starts with the plus signal "+". Discovered this because my app does a simple query just to check if an existing data exists like cellphones (with international codes starting with "+").

func DataExist(k string, d string) bool {
	var v map[string]interface{}
	uRef, err := fdb.Ref("users/")
	if err != nil {
		fmt.Printf("Error")
		return false
	}
	if err := uRef.StartAtValue(d).EndAtValue(d).LimitToFirst(1).OrderBy(k).Value(&v); err != nil {
		log.Fatal(err)
		return false
	}
	if len(v) == 0 {
		return false
	}
	return true
}

Calling it:

p := fbdb.DataExist("phone", "+5561999999999")
log.Println("Phone Exist? ", p)

   returns -> **Phone Exist?  false** 

If you put any value after "+" like "+newstring" and update your DB, it also does not work. I've tried with other symbols like "=,#,-" and they seems to work.

@zabawaba99 zabawaba99 added the bug label Oct 10, 2017
@zabawaba99
Copy link
Owner

Hey @ArturHS, thanks for opening up the issue. I went ahead and isolated the code that creates the query string on this Go Playground. It's odd that another special character works since they all get escaped when encoding it.

Can you verify that the data stored in Firebase has the leading +?

@arturscheiner
Copy link
Author

arturscheiner commented Oct 11, 2017

Hi @zabawaba99, in Firebase the data stored is a string like this "+5561999999999", right now i'm changing my app not to write the "+" sign. It is, indeed, a strange behavior. I was playing around with other chars. These are my findings:

if string starts with "+" returns -> false
if string starts with "-=@$^*()_" returns -> true
if string starts with "&" doesn't run -> "error" : "Constraint index field must be a JSON primitive"
if string starts with "#" doesn't run -> "error" : "orderBy must be defined when other query parameters are defined"
if string starts with "%" doesn't run -> "error" : "Bad Request"

Maybe this problem is related with the way chars are encoded in the firebase calls...

@rockwotj
Copy link

This is an issue with the realtime database's handling of URL Decoding and is a very old bug.

There is a workaround, this will work if you add a header of X-Firebase-Decoding: 1 to the request. At some point in the future we'll fix this correctly without needing the header.

@zabawaba99
Copy link
Owner

context for anyone else following along firebase/firebase-admin-go#186

@rockwotj - Would adding X-Firebase-Decoding: 1 to every request be ok or would we need to add it only to requests that have these query params?

@rockwotj
Copy link

You should just add it all the time

@rockwotj
Copy link

rockwotj commented Mar 3, 2019

This should be fixed now and you don't need to specify the header.

@zabawaba99
Copy link
Owner

Closing issue as repository is being archived.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants