-
-
Notifications
You must be signed in to change notification settings - Fork 93
Add validation for font-faces property #1351
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
Changes from all commits
325567f
2fd55f8
b0fa066
4a3cebe
de4f27c
490050c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,80 @@ | ||||||||||||||||||||||||||||||||
| import {ValidationError} from '../error/validation_error'; | ||||||||||||||||||||||||||||||||
| import {getType} from '../util/get_type'; | ||||||||||||||||||||||||||||||||
| import {isObjectLiteral} from '../util/is_object_literal'; | ||||||||||||||||||||||||||||||||
| import {validateObject} from './validate_object'; | ||||||||||||||||||||||||||||||||
| import {validateString} from './validate_string'; | ||||||||||||||||||||||||||||||||
| import v8 from '../reference/v8.json' with {type: 'json'}; | ||||||||||||||||||||||||||||||||
| import type {StyleSpecification} from '../types.g'; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| interface ValidateFontFacesOptions { | ||||||||||||||||||||||||||||||||
| key: string; | ||||||||||||||||||||||||||||||||
| value: unknown; | ||||||||||||||||||||||||||||||||
| styleSpec: typeof v8; | ||||||||||||||||||||||||||||||||
| style: StyleSpecification; | ||||||||||||||||||||||||||||||||
| validateSpec: Function; | ||||||||||||||||||||||||||||||||
|
Comment on lines
+8
to
+14
|
||||||||||||||||||||||||||||||||
| interface ValidateFontFacesOptions { | |
| key: string; | |
| value: unknown; | |
| styleSpec: typeof v8; | |
| style: StyleSpecification; | |
| validateSpec: Function; | |
| import type {ValidationError} from '../error/validation_error'; | |
| interface ValidateFontFacesOptions { | |
| key: string; | |
| value: unknown; | |
| styleSpec: typeof v8; | |
| style: StyleSpecification; | |
| validateSpec: (options: { key: string; value: unknown; styleSpec: typeof v8; style: StyleSpecification; }) => ValidationError[]; |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using any[] cast bypasses type safety. Since fontValueType === 'array' was already checked on line 46, consider using Array<unknown> instead of any[] for better type safety.
| for (const [i, fontFace] of (fontValue as any[]).entries()) { | |
| for (const [i, fontFace] of (fontValue as Array<unknown>).entries()) { |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "version": 8, | ||
| "sources": {}, | ||
| "layers": [], | ||
| "font-faces": [] | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| [ | ||
| { | ||
| "message": "font-faces: object expected, array found", | ||
| "line": 5 | ||
| } | ||
| ] | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "version": 8, | ||
| "sources": {}, | ||
| "layers": [], | ||
| "font-faces": true | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| [ | ||
| { | ||
| "message": "font-faces: object expected, boolean found", | ||
| "line": 5 | ||
| } | ||
| ] | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "version": 8, | ||
| "sources": {}, | ||
| "layers": [], | ||
| "font-faces": 123 | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| [ | ||
| { | ||
| "message": "font-faces: object expected, number found", | ||
| "line": 5 | ||
| } | ||
| ] | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "version": 8, | ||
| "sources": {}, | ||
| "layers": [], | ||
| "font-faces": { | ||
| "Noto Sans": [{ | ||
| "url": "https://example.com/font.ttf", | ||
| "unicode-range": ["U+1780-17FF"] | ||
| }] | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [] | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "version": 8, | ||
| "sources": {}, | ||
| "layers": [], | ||
| "font-faces": {} | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [] | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "version": 8, | ||
| "sources": {}, | ||
| "layers": [], | ||
| "font-faces": { | ||
| "Noto Sans": "https://example.com/font.ttf" | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [] | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "version": 8, | ||
| "sources": {}, | ||
| "layers": [], | ||
| "font-faces": "invalid string" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [ | ||
| { | ||
| "message": "font-faces: object expected, string found", | ||
| "line": 5 | ||
| } | ||
| ] |
Uh oh!
There was an error while loading. Please reload this page.