arpithparikh / rdfquery

Automatically exported from code.google.com/p/rdfquery
0 stars 0 forks source link

regular expression for the XML datatype ‘duration’ incorrectly requires a decimal point in the seconds #24

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Parsing an RDF/XML value with datatype
http://www.w3.org/2001/XMLSchema#duration fails if the value contains
an integer seconds component.  My reading of the XML datatype spec is
that the ‘decimal’ does not require the decimal point.

What is the expected output? What do you see instead?

e.g. "PT12.0S" will parse, returning:

    ["PT12.0S", undefined, undefined, undefined, undefined, undefined, undefined, "12.0"]

While "PT12S" will not match, returning null.

What version of the product are you using? On what operating system?

Firefox 3.6.10, GNU/Linux.

Please provide any additional information below.

The fix is to add a '?' to the decimal portion of the seconds group in
the regexp.  The patch (to SVN head) is:

diff --git a/jquery.datatype.js b/jquery.datatype.js
index c30dae4..c871e01 100644
--- a/jquery.datatype.js
+++ b/jquery.datatype.js
@@ -251,7 +251,7 @@
   };

   $.typedValue.types['http://www.w3.org/2001/XMLSchema#duration'] = {
-    regex: 
/^([\-\+])?P(?:([0-9]+)Y)?(?:([0-9]+)M)?(?:([0-9]+)D)?(?:T(?:([0-9]+)H)?(?:([0-9
]+)M)?(?:([0-9]+(?:\.[0-9]+))?S)?)$/,
+    regex: 
/^([\-\+])?P(?:([0-9]+)Y)?(?:([0-9]+)M)?(?:([0-9]+)D)?(?:T(?:([0-9]+)H)?(?:([0-9
]+)M)?(?:([0-9]+(?:\.[0-9]+)?)?S)?)$/,
     /** @ignore */
     validate: function (v) {
       var m = this.regex.exec(v);

Original issue reported on code.google.com by d.j.lamb...@gmail.com on 11 Oct 2010 at 12:26

GoogleCodeExporter commented 8 years ago
Applied patch

Original comment by d.j.lamb...@gmail.com on 30 Nov 2010 at 2:26