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