| @@ -266,9 +266,9 @@ | ||
| 266 | 266 | $result['errors'] = array_merge($result['errors'], $field_validation['errors']); |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | // 6. Validate data types and formats |
| 270 | - $format_validation = $this->validate_data_formats($sanitized_data, $schema_type, $schema_data); | |
| 270 | + $format_validation = $this->validate_data_formats($sanitized_data, $schema_type); | |
| 271 | 271 | if (!$format_validation['valid']) { |
| 272 | 272 | $result['errors'] = array_merge($result['errors'], $format_validation['errors']); |
| 273 | 273 | } |
| 274 | 274 | $result['warnings'] = array_merge($result['warnings'], $format_validation['warnings']); |
| @@ -582,12 +582,11 @@ | ||
| 582 | 582 | * @since 1.0.0 |
| 583 | 583 | * |
| 584 | 584 | * @param array $schema_data Schema data |
| 585 | 585 | * @param string $schema_type Schema type |
| 586 | - * @param array $raw_data Schema data as submitted, before sanitization. | |
| 587 | 586 | * @return array Validation result |
| 588 | 587 | */ |
| 589 | - private function validate_data_formats(array $schema_data, string $schema_type, array $raw_data = []): array { | |
| 588 | + private function validate_data_formats(array $schema_data, string $schema_type): array { | |
| 590 | 589 | $result = ['valid' => true, 'errors' => [], 'warnings' => []]; |
| 591 | 590 | |
| 592 | 591 | foreach ($schema_data as $field => $value) { |
| 593 | 592 | // sameAs is a list, so its members never reached the string branch |
| @@ -593,27 +592,15 @@ | ||
| 593 | 592 | // sameAs is a list, so its members never reached the string branch |
| 594 | 593 | // below and free text entered in a social-profile field saved |
| 595 | 594 | // cleanly, then shipped as invalid structured data (#480). |
| 596 | 595 | if (is_array($value) && in_array($field, ['url', 'sameAs', 'logo', 'image'], true)) { |
| 597 | - // Validated after sanitization, but reported as entered: | |
| 598 | - // esc_url_raw() turns "not a url" into "http://not%20a%20url", | |
| 599 | - // which the user never typed (#949 review). | |
| 600 | - $items = $this->url_candidates($value); | |
| 601 | - $raw_items = is_array($raw_data[$field] ?? null) ? $this->url_candidates($raw_data[$field]) : []; | |
| 602 | - if (count($raw_items) !== count($items)) { | |
| 603 | - // A non-string member sanitized into a string would shift | |
| 604 | - // the positions; fall back rather than name the wrong one. | |
| 605 | - $raw_items = []; | |
| 606 | - } | |
| 607 | - | |
| 608 | - foreach ($items as $index => $item) { | |
| 609 | - if ('' === trim($item)) { | |
| 596 | + foreach ($value as $item) { | |
| 597 | + if (!is_string($item) || '' === trim($item)) { | |
| 610 | 598 | continue; |
| 611 | 599 | } |
| 612 | 600 | |
| 613 | 601 | if (!$this->is_valid_url($item)) { |
| 614 | - $shown = $raw_items[$index] ?? $item; | |
| 615 | - $result['errors'][] = "Invalid URL format for field: {$field} ({$shown})"; | |
| 602 | + $result['errors'][] = "Invalid URL format for field: {$field} ({$item})"; | |
| 616 | 603 | $result['valid'] = false; |
| 617 | 604 | } |
| 618 | 605 | } |
| 619 | 606 | |
| @@ -646,47 +633,8 @@ | ||
| 646 | 633 | } |
| 647 | 634 | } |
| 648 | 635 | |
| 649 | 636 | return $result; |
| 650 | - } | |
| 651 | - | |
| 652 | - /** | |
| 653 | - * The URL strings inside an array-valued URL field. | |
| 654 | - * | |
| 655 | - * The field is either a list (`sameAs`, several `image` URLs) or a single | |
| 656 | - * node such as the `ImageObject` Schema_Builder emits for a configured | |
| 657 | - * logo. Checking every member of a node URL-checked its `@type` and | |
| 658 | - * `width`, so "ImageObject" failed as an invalid URL and the deploy route | |
| 659 | - * skipped — then retired — the site's Organization (#949). Only a node's | |
| 660 | - * `url` / `contentUrl` are URLs; a list may hold strings or such nodes. | |
| 661 | - * | |
| 662 | - * @since 2.14.1 | |
| 663 | - * | |
| 664 | - * @param array $value Array-valued URL field. | |
| 665 | - * @return string[] URL strings to validate. | |
| 666 | - */ | |
| 667 | - private function url_candidates(array $value): array { | |
| 668 | - $node_urls = static function (array $node): array { | |
| 669 | - return array_values(array_filter( | |
| 670 | - [$node['url'] ?? null, $node['contentUrl'] ?? null], | |
| 671 | - 'is_string' | |
| 672 | - )); | |
| 673 | - }; | |
| 674 | - | |
| 675 | - if (array_values($value) !== $value) { | |
| 676 | - return $node_urls($value); | |
| 677 | - } | |
| 678 | - | |
| 679 | - $urls = []; | |
| 680 | - foreach ($value as $item) { | |
| 681 | - if (is_string($item)) { | |
| 682 | - $urls[] = $item; | |
| 683 | - } elseif (is_array($item)) { | |
| 684 | - $urls = array_merge($urls, $node_urls($item)); | |
| 685 | - } | |
| 686 | - } | |
| 687 | - | |
| 688 | - return $urls; | |
| 689 | 637 | } |
| 690 | 638 | |
| 691 | 639 | /** |
| 692 | 640 | * Validate content lengths |