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

Inputting symbols and placeholders like £, $ and % #2

Open
juba666 opened this issue Jun 26, 2019 · 3 comments
Open

Inputting symbols and placeholders like £, $ and % #2

juba666 opened this issue Jun 26, 2019 · 3 comments

Comments

@juba666
Copy link
Owner

juba666 commented Jun 26, 2019

Describe the bug
Inputting symbols and placeholders like £ , $ and % bypasses validation rules

To Reproduce
Steps to reproduce the behavior:

  1. Open cic.go and choose choice 1
  2. Input 0 for Principal Amount
  3. Input £0 for Principal Amount

Expected behavior
First input triggers error and goto pa works, second input triggers error message but doesnt goto pa, instead skips to else statement

func calcFA() {
var p float64
var s string
var n float64
var r float64
pa:
fmt.Print("Enter a Principal Amount(£): ")
fmt.Scanf("%f\n", &p)
if !(p > 0) {
        fmt.Println("ERROR: you did not enter a number greater than zero, or included a symbol")
		goto pa
} else {
@juba666
Copy link
Owner Author

juba666 commented Jun 27, 2019

I tried strings.ContainsRune function but still needs work
commit: cd7ba3b

import (
"strings"
)
...
...
...
fmt.Print("Enter a Principal Amount(£): ")
fmt.Scanf("%f\n", &p)
tp := fmt.Sprintf("%f", p)
if !(p > 0) || ((strings.ContainsRune(tp, '\u00a3')) || ((strings.ContainsRune(tp, '$')))) {
        fmt.Println("ERROR: you did not enter a number greater than zero, or included a currency symbol")
		calcFA()
} else {

@juba666 juba666 changed the title Inputting symbols/placeholders like '£' , '$' and '%' Inputting symbols and placeholders like '£' , '$' and '%' Jun 28, 2019
@juba666 juba666 changed the title Inputting symbols and placeholders like '£' , '$' and '%' Inputting symbols and placeholders like £, $ and % Jun 28, 2019
@juba666
Copy link
Owner Author

juba666 commented Jun 28, 2019

[FIXED]

pa:
fmt.Print("Enter a Principal Amount(£): ")
fmt.Scanf("%f\n", &p)
sp := fmt.Sprintf("%f", p)
if !(p > 0) || ((strings.ContainsRune(sp, '\u00a3')) || ((strings.ContainsRune(sp, '$')))) {
        fmt.Println("ERROR: you did not enter a number greater than zero, or included a symbol")
		goto pa
} else {

@juba666 juba666 closed this as completed Jun 28, 2019
@juba666 juba666 reopened this Jun 30, 2019
@juba666
Copy link
Owner Author

juba666 commented Jun 30, 2019

$ and % still bypass condition :-/ but no problematic loops caused so this issue is not a priority

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