Clint,

I'm pretty sure I've figured it out and have a fix.  But, you will
want to check for yourself.  It does pass the tests I did with a
schema and sample XML instance document, which I created that
contain a pattern with a vertical bar and a test case for it.

A patch is attached.  And, the fix has been pushed to Bitbucket at:
https://bitbucket.org/dkuhlman/generateds.

The problem was that, when vertical bars (if not escaped with a
backslash) are in the pattern, we are actually matching against two
(or more, I suppose) patterns, and *each* of those patterns has to
be surrounded by "^" and "$" so that we match on the pattern and
nothing more.  Before this fix, I was surrounding the entire
pattern, but not the individual alternative patterns.

When you try it, please let me know whether you agree that it fixes
the problem that you identified.

I'll make a new release later, when I have a few more things to fix.

Thanks again for working with me on this.  I appreciate the help.

Dave

-- 

Dave Kuhlman
http://www.davekuhlman.org
diff -r 1ba546514a3e generateDS.py
--- a/generateDS.py     Tue Nov 22 13:19:29 2016 -0800
+++ b/generateDS.py     Fri Dec 30 15:29:00 2016 -0800
@@ -4309,6 +4309,15 @@
     return targetValue
 
 
+Vbar_repl_pat = re.compile('([^\\\])\|')
+
+
+# Replace vertical bars with "$|^", unless escaped with backslash.
+def replaceVbars(instr):
+    outstr, count = re.subn(Vbar_repl_pat, '\\1$|^', instr)
+    return outstr
+
+
 # Generate validation code for each restriction.
 # Recursivly call to process possible chain of base types.
 def processValidatorBodyRestrictions(
@@ -4320,7 +4329,7 @@
         pats1 = restriction.xpath(
             "./xs:pattern/@value", namespaces=ns)
         if pats1:
-            pats2 = ['^%s$' % (p1, ) for p1 in pats1]
+            pats2 = ['^{}$'.format(replaceVbars(p1)) for p1 in pats1]
             patterns1.append(pats2)
         #
         # Check for and generate code for each possible type of restriction.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users

Reply via email to