| 871 | // JSON or does not match the expected shape, so malformed or untrusted data is ignored rather |
| 872 | // than throwing or being inserted into the field. |
| 873 | function parseSegments(json: string): TokenFieldSegment[] | null { |
| 874 | try { |
| 875 | let data = JSON.parse(json); |
| 876 | if (Array.isArray(data) && data.length > 0 && data.every(isValidSegment)) { |
| 877 | return data; |
| 878 | } |
| 879 | } catch { |
| 880 | // Ignore invalid clipboard data. |
| 881 | } |
| 882 | return null; |
| 883 | } |
| 884 | |
| 885 | function isValidSegment(segment: unknown): segment is TokenFieldSegment { |
| 886 | return ( |