• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rokucommunity / brighterscript / 28942370337

08 Jul 2026 12:24PM UTC coverage: 88.373% (-0.02%) from 88.392%
28942370337

Pull #1742

github

web-flow
Merge 2e72bc9ad into 0f0c30b5c
Pull Request #1742: Validate SceneGraph node types and fields in xml components

9182 of 10930 branches covered (84.01%)

Branch coverage included in aggregate %.

38 of 48 new or added lines in 3 files covered. (79.17%)

11408 of 12369 relevant lines covered (92.23%)

2030.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.64
/src/bscPlugin/validation/FieldTypeValidator.ts
1
/**
2
 * Best-effort validation of a SceneGraph field value written as an xml attribute string.
3
 *
4
 * Intentionally conservative: only unambiguous scalar types are checked. Anything ambiguous (strings,
5
 * nodes, uris, arrays, vectors, enums/option-strings, unknown types, etc.) passes, so we never emit a
6
 * false positive for the many field types whose valid literal form is hard to pin down from xml alone.
7
 *
8
 * @param value the (unquoted) attribute value
9
 * @param type the field's declared type (e.g. `integer`, `float`, `boolean`, `color`, `option string`)
10
 * @returns true when the value is valid for the type, or when the type isn't one we confidently validate
11
 */
12
export function isValidSceneGraphFieldValue(value: string, type: string): boolean {
1✔
13
    const validator = scalarValidators[normalizeFieldType(type)];
13✔
14
    //no validator for this type -> assume valid
15
    return validator ? validator(value ?? '') : true;
13!
16
}
17

18
function normalizeFieldType(type: string): string {
19
    let normalized = (type ?? '').trim().toLowerCase();
13!
20
    //"option string", "value string", etc. are all just strings
21
    if (normalized.endsWith(' string')) {
13!
NEW
22
        normalized = 'string';
×
23
    }
24
    return normalized;
13✔
25
}
26

27
const integerPattern = /^[+-]?\d+$/;
1✔
28
const floatPattern = /^[+-]?(\d+\.?\d*|\.\d+)$/;
1✔
29
const booleanPattern = /^(true|false)$/i;
1✔
30
const colorPattern = /^(#[0-9a-f]{3,4}|#[0-9a-f]{6}|#[0-9a-f]{8}|0x[0-9a-f]{6}|0x[0-9a-f]{8})$/i;
1✔
31

32
const scalarValidators: Record<string, (value: string) => boolean> = {
1✔
NEW
33
    integer: value => integerPattern.test(value),
×
NEW
34
    int: value => integerPattern.test(value),
×
NEW
35
    longinteger: value => integerPattern.test(value),
×
36
    float: value => floatPattern.test(value),
4✔
NEW
37
    double: value => floatPattern.test(value),
×
NEW
38
    time: value => floatPattern.test(value),
×
NEW
39
    boolean: value => booleanPattern.test(value),
×
NEW
40
    bool: value => booleanPattern.test(value),
×
NEW
41
    color: value => colorPattern.test(value)
×
42
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc