Skip to content

Commit

Permalink
Made the HTML Microdata parser ignore invalid properties
Browse files Browse the repository at this point in the history
  • Loading branch information
jkphl committed May 28, 2017
1 parent 5f0f6a2 commit 9c755e3
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 40 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,40 +2,54 @@

All Notable changes to *jkphl/rdfa-lite-microdata* will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/). This project adheres to [Semantic Versioning](http://semver.org/).

## [0.4.1] - 2017-05-28

### Changed

* Made the HTML Microdata parser ignore invalid properties

## [0.4.0] - 2017-04-24

### Changed

* Released the Microdata property name constraints
* Swapped in the [dom-factory](https://github.com/jkphl/dom-factory) HTML5/XML parser

### Removed

* Custom HTML parser error handling

## [0.3.1] - 2017-03-24

### Added

* Dedicated exception for HTML parsing errors
* Added custom HTML parsing error handling ([#4](https://github.com/jkphl/rdfa-lite-microdata/issues/4))

## [0.3.0] - 2017-03-17

### Added

* Support for enhanced property lists and property names
* IRI mode (IRI based item types and property names)

## [0.2.1] - 2017-03-11

### Fixed

* Fixed property cache bug

### Changed

* Prefixed HTML Microdata property names with schema.org vocabulary URI (consistency with RDFa Lite 1.1 parsing results)

## [0.2.0] - 2017-03-03

### Added

* Support for HTML5 documents
* Support for DOMDocument parsing

## [0.1.0] - 2017-02-20

Initial release
Expand Up @@ -37,6 +37,7 @@
namespace Jkphl\RdfaLiteMicrodata\Infrastructure\Parser;

use Jkphl\RdfaLiteMicrodata\Application\Context\ContextInterface;
use Jkphl\RdfaLiteMicrodata\Domain\Exceptions\RuntimeException;
use Jkphl\RdfaLiteMicrodata\Domain\Property\Property;
use Jkphl\RdfaLiteMicrodata\Domain\Thing\ThingInterface;
use Jkphl\RdfaLiteMicrodata\Domain\Vocabulary\VocabularyInterface;
Expand Down Expand Up @@ -65,7 +66,11 @@ protected function processPropertyPrefixName($prefix, $name, \DOMElement $elemen
{
$vocabulary = $this->getVocabulary($prefix, $context);
if ($vocabulary instanceof VocabularyInterface) {
$context = $this->addProperty($element, $context, $name, $vocabulary, $last);
try {
$context = $this->addProperty($element, $context, $name, $vocabulary, $last);
} catch (RuntimeException $e) {
// Skip invalid property
}
}

return $context;
Expand Down
12 changes: 12 additions & 0 deletions src/RdfaLiteMicrodata/Tests/Domain/PropertyTest.php
Expand Up @@ -81,6 +81,18 @@ public function testInvalidPropertyName()
new Property('', $vocabulary, 'value');
}

/**
* Test another invalid property name
*
* @expectedException \Jkphl\RdfaLiteMicrodata\Domain\Exceptions\RuntimeException
* @expectedExceptionCode 1486848618
*/
public function testAnotherInvalidPropertyName()
{
$vocabulary = new Vocabulary(VocabularyTest::SCHEMA_ORG_URI);
new Property('name-width-dash', $vocabulary, 'value');
}

/**
* Test the property list
*/
Expand Down
18 changes: 0 additions & 18 deletions src/RdfaLiteMicrodata/Tests/Fixtures/empty-property-microdata.html

This file was deleted.

9 changes: 0 additions & 9 deletions src/RdfaLiteMicrodata/Tests/Fixtures/empty-property.xhtml

This file was deleted.

1 change: 1 addition & 0 deletions src/RdfaLiteMicrodata/Tests/Fixtures/movie-microdata.html
Expand Up @@ -7,6 +7,7 @@
<body>
<div itemscope itemtype="http://schema.org/Movie" itemid="http://www.imdb.com/title/tt0499549/">
<h1 itemprop="name">Avatar</h1>
<h1 itemprop="sub-title">James Cameron’s Avatar</h1>
<div itemprop="director producer" itemscope itemtype="http://schema.org/Person">
Director: <span itemprop="name">James Cameron</span> (born <span
itemprop="birthDate">August 16, 1954</span>,
Expand Down
12 changes: 0 additions & 12 deletions src/RdfaLiteMicrodata/Tests/Ports/MicrodataParserTest.php
Expand Up @@ -144,16 +144,4 @@ public function testInvalidFile()
{
(new Microdata())->parseHtmlFile('invalid');
}

/**
* Test a HTML runtime exception
*
* @expectedException \Jkphl\RdfaLiteMicrodata\Ports\Exceptions\RuntimeException
*/
public function testRuntimeException()
{
(new Microdata())->parseHtmlFile(
dirname(__DIR__).DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'empty-property-microdata.html'
);
}
}

0 comments on commit 9c755e3

Please sign in to comment.