| 727 | // JSON or does not match the expected shape, so malformed or untrusted data is ignored rather |
| 728 | // than throwing or being inserted into the field. |
| 729 | function parseSegments(json: string): TokenFieldSegment[] | null { |
| 730 | try { |
| 731 | let data = JSON.parse(json); |
| 732 | if (Array.isArray(data) && data.length > 0 && data.every(isValidSegment)) { |
| 733 | return data; |
| 734 | } |
| 735 | } catch { |
| 736 | // Ignore invalid clipboard data. |
| 737 | } |
| 738 | return null; |
| 739 | } |
| 740 | |
| 741 | function isValidSegment(segment: unknown): segment is TokenFieldSegment { |
| 742 | return ( |