Sophivorus has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/347210 )

Change subject: Fix buggy regex to match <ref> names with spaces
......................................................................

Fix buggy regex to match <ref> names with spaces

Patch by Uglemat, thanks!

Bug T162488

Change-Id: Iefd4ba03751f6cd7d88975580198bf1f34a6143d
---
M proveit.js
1 file changed, 5 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikipedia/gadgets/ProveIt 
refs/changes/10/347210/1

diff --git a/proveit.js b/proveit.js
index 551b9d5..27220ab 100755
--- a/proveit.js
+++ b/proveit.js
@@ -274,12 +274,12 @@
                // First look for all the citations and store them in an array 
for later
                var wikitext = proveit.getTextbox().val(),
                        citations = [],
-                       citationsRegExp = 
/<\s*ref\s+name\s*=\s*["|']?\s*([^"'\s]+)\s*["|']?\s*\/\s*>/ig, // Three 
patterns: <ref name="foo" />, <ref name='foo' /> and <ref name=foo />
+                       citationsRegExp = 
/<\s*ref\s+name\s*=\s*((["'])(((?!\2).)+)\2|([^\s'">\/]+))\s*\/\s*>/ig, // 
Three patterns: <ref name="foo" />, <ref name='foo' /> and <ref name=foo />
                        match,
                        citation;
 
-               while ( ( match = citationsRegExp.exec( wikitext ) ) ) {
-                       citation = new proveit.Citation({ 'name': match[1], 
'index': match.index, 'string': match[0] });
+           while ( ( match = citationsRegExp.exec( wikitext ) ) ) {
+                       citation = new proveit.Citation({ 'name': match[3] || 
match[5], 'index': match.index, 'string': match[0] });
                        citations.push( citation );
                }
 
@@ -330,9 +330,9 @@
                // Extract the reference name, if any
                // Three patterns: <ref name="foo">, <ref name='foo'> and <ref 
name=foo>
                var referenceName = null,
-                       match = referenceString.match( 
/<[\s]*ref[\s]*name[\s]*=[\s]*(?:(?:\"(.*?)\")|(?:\'(.*?)\')|(?:(.*?)))[\s]*>/i 
);
+                       match = referenceString.match( 
/<\s*ref\s+name\s*=\s*((["'])(((?!\2).)+)\2|([^\s'">]+))\s*\s*>/i );
                if ( match ) {
-                       referenceName = match[1] || match[2] || match[3];
+                       referenceName = match[3] || match[5];
                }
 
                // Get the index

-- 
To view, visit https://gerrit.wikimedia.org/r/347210
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iefd4ba03751f6cd7d88975580198bf1f34a6143d
Gerrit-PatchSet: 1
Gerrit-Project: wikipedia/gadgets/ProveIt
Gerrit-Branch: master
Gerrit-Owner: Sophivorus <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to