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

bug [v2] BaseNumericInterface min 0 #361

Closed
erwanito12 opened this issue Jan 10, 2024 · 3 comments
Closed

bug [v2] BaseNumericInterface min 0 #361

erwanito12 opened this issue Jan 10, 2024 · 3 comments
Labels
bug Something isn't working
Projects

Comments

@erwanito12
Copy link

export class BaseNumericInterface extends NodeInterface implements IValidator {
public min?: number;
public max?: number;

constructor(name: string, value: number, min?: number, max?: number) {
    super(name, value);
    this.min = min;
    this.max = max;
}

public validate(v: number) {
    return (!this.min || v >= this.min) && (!this.max || v <= this.max);
}

}
When this.min is 0, the !this.min expression returns true, because in JavaScript, 0 is considered a false value. This means that the v >= this.min part is never evaluated when min is 0.

To correct this problem, you must explicitly check whether min and max are undefined rather than evaluating them as booleans.

public validate(v: number) {
return (this.min === undefined || v >= this.min) && (this.max === undefined || v <= this.max);
}

@erwanito12 erwanito12 changed the title bug BaseNumericInterface valeur min 0 bug BaseNumericInterface min 0 Jan 10, 2024
@erwanito12 erwanito12 changed the title bug BaseNumericInterface min 0 bug [v2] BaseNumericInterface min 0 Jan 10, 2024
@starker-xp
Copy link
Contributor

Do you use Js or Ts?
If you use ts, you probably have the strictNullChecks option set to false.

@erwanito12
Copy link
Author

i use Ts,
tsconfig.json:
{ "compilerOptions": { "target": "esnext", "module": "esnext", "strict": true, "jsx": "preserve", "moduleResolution": "node", "experimentalDecorators": true, "skipLibCheck": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "forceConsistentCasingInFileNames": true, "useDefineForClassFields": true, "baseUrl": ".", "noImplicitAny": true, "sourceMap": true, "allowJs": true, "types": [ "webpack-env" ], "paths": { "@/*": [ "src/*" ] }, "lib": [ "esnext", "dom", "dom.iterable", "scripthost" ] }, "include": [ "src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts", "tests/**/*.tsx" ], "exclude": [ "node_modules" ] }

@newcat newcat added the bug Something isn't working label Jan 13, 2024
@newcat newcat added this to Done but not released in V2 Jan 13, 2024
@newcat
Copy link
Owner

newcat commented Feb 8, 2024

Fixed in v2.4.0

@newcat newcat closed this as completed Feb 8, 2024
@newcat newcat moved this from Done but not released to Done in V2 Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
V2
  
Done
Development

No branches or pull requests

3 participants