Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking 'len' and 'lang' in a tag could lead to problems using a oneof #15

Open
threehook opened this issue Dec 14, 2022 · 0 comments
Open

Comments

@threehook
Copy link

Hi,

I found a bug in faker.go.

In function extractStringFromTag there is the following code:

	if strings.Contains(tag, Length) {
		lenParts := strings.SplitN(findLenReg.FindString(tag), Equals, -1)
		if len(lenParts) != 2 {
			return nil, fmt.Errorf(fakerErrors.ErrWrongFormattedTag, tag)
		}
		strlen, _ = strconv.Atoi(lenParts[1])
	}

This checks if the tag contains the word len, its contents is split by using an equal sign as separator.
It throws an error if this fails.
In our specific case we use a oneof in our tag. One of the possible options is 'Bedrijfsmatig handelen'.
This text contains the word len so faker thinks this must be something like len=10, but it's not.
So our unit tests and app fail.

Note also the word 'lang' could be part of a oneof, so should also be mitigated.
I think extending the checks with && !isOneOfTag could work.

Could you please have a look at it?

Regards,
Ton

@threehook threehook changed the title Checking 'len' and 'lang' in a tag could lead to problem using a oneof Checking 'len' and 'lang' in a tag could lead to problems using a oneof Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant