deepmodeling / deepmodeling/dpgui

[Code scan] Reject fractional values for integer fields

Open
#560 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Vue
Stars
9
Forks
5
PR merge metrics
No merged PRs in 30d

Description

This issue was found during a Codex global code scan of the repository.

Baseline commit: e3c5b38a99eb7ab778b5d8c68a5ed4ddf6cf91b3

Problem

Integer inputs use the same numeric validation and serialization path as floats. The validator accepts any value that is not `NaN`, and export uses `Number.parseFloat()` for both `int` and `float`.

Code references:
https://github.com/deepmodeling/dpgui/blob/e3c5b38a99eb7ab778b5d8c68a5ed4ddf6cf91b3/src/components/dargs/DargsItem.vue#L136-L139
https://github.com/deepmodeling/dpgui/blob/e3c5b38a99eb7ab778b5d8c68a5ed4ddf6cf91b3/src/components/dargs/DargsItem.vue#L342-L349

Relevant snippet:
```js
...(['int', 'float'].includes(select_type) ? rules.number : []),
```

```js
if (!(this.select_type == "str")) {
return Number.parseFloat(this.value);
}
```

Impact

A field declared as `int` can accept and export a fractional value such as `1.5`, producing invalid or semantically wrong input for downstream tools.

Suggested fix

Add a separate integer rule, for example based on `Number.isInteger(Number(value))`, and serialize `int` fields with an integer conversion after validation.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.