Repository: crawler-commons/crawler-commons (java)

Issue:
[sitemaps] Replace priority "NaN" by default value
The priority value in
```xml
    <url>
        <priority>NaN</priority>
        <lastmod>2020-05-22</lastmod>
        <changefreq>monthly</changefreq>
        <loc>...</loc>
    </url>
```
is successfully parsed as double, however, the value (Double.NaN) isn't inside the [allowed range](https://www.sitemaps.org/protocol.html#xmlTagDefinitions) ([0.0,1.0]).

Pull request description:
[sitemaps] Replace priority "NaN" by default value, fixes #296

Patch:
diff --git a/CHANGES.txt b/CHANGES.txt
index f2e6a76..d2366ae 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -3,6 +3,7 @@ Crawler-Commons Change Log
 Current Development 1.2-SNAPSHOT (yyyy-mm-dd)
 - [SiteMapParser] Document options *strict* and *allowPartial* in SiteMapParser constructors (sebastian-nagel) #267
 - [Robots] Maximum values (crawl-delay and warnings): document and make visible (sebastian-nagel, Avi Hayun) #276
+- [sitemaps] Replace priority "NaN" by default value (sebastian-nagel) #296
 - [Sitemaps] Adding duration to the map generated by VideoAttributes.asMap (evanhalley)  #300
 
 Release 1.1 (2020-06-29)
diff --git a/src/main/java/crawlercommons/sitemaps/SiteMapURL.java b/src/main/java/crawlercommons/sitemaps/SiteMapURL.java
index 1f1c18b..ef34b62 100644
--- a/src/main/java/crawlercommons/sitemaps/SiteMapURL.java
+++ b/src/main/java/crawlercommons/sitemaps/SiteMapURL.java
@@ -205,7 +205,7 @@ public class SiteMapURL implements Serializable {
     public void setPriority(double priority) {
 
         // Ensure proper value
-        if (priority < 0.0 || priority > 1.0) {
+        if (priority < 0.0 || priority > 1.0 || Double.isNaN(priority)) {
             this.priority = DEFAULT_PRIORITY;
             LOG.warn("Can't set the priority to {}, Priority should be between 0 to 1, reverting to default priority value: {}", priority, DEFAULT_PRIORITY);
         } else {


Test patch:
diff --git a/src/test/java/crawlercommons/sitemaps/SiteMapURLTest.java b/src/test/java/crawlercommons/sitemaps/SiteMapURLTest.java
index 9204412..c562547 100644
--- a/src/test/java/crawlercommons/sitemaps/SiteMapURLTest.java
+++ b/src/test/java/crawlercommons/sitemaps/SiteMapURLTest.java
@@ -43,5 +43,18 @@ public class SiteMapURLTest {
         assertEquals(0.6, siteMapURL.getPriority(), 0);
         siteMapURL.setPriority("1.1");
         assertEquals(SiteMapURL.DEFAULT_PRIORITY, siteMapURL.getPriority(), 0);
+
+        siteMapURL.setPriority("NaN");
+        assertEquals(SiteMapURL.DEFAULT_PRIORITY, siteMapURL.getPriority(), 0);
+        siteMapURL.setPriority(Double.NaN);
+        assertEquals(SiteMapURL.DEFAULT_PRIORITY, siteMapURL.getPriority(), 0);
+        siteMapURL.setPriority("Infinity");
+        assertEquals(SiteMapURL.DEFAULT_PRIORITY, siteMapURL.getPriority(), 0);
+        siteMapURL.setPriority(Double.POSITIVE_INFINITY);
+        assertEquals(SiteMapURL.DEFAULT_PRIORITY, siteMapURL.getPriority(), 0);
+        siteMapURL.setPriority("-Infinity");
+        assertEquals(SiteMapURL.DEFAULT_PRIORITY, siteMapURL.getPriority(), 0);
+        siteMapURL.setPriority(Double.NEGATIVE_INFINITY);
+        assertEquals(SiteMapURL.DEFAULT_PRIORITY, siteMapURL.getPriority(), 0);
     }
 }