Last Comment Bug 398962 - Add regular expression function for -moz-document rules
: Add regular expression function for -moz-document rules
: dev-doc-complete
Product: Core
Classification: Components
Component: CSS Parsing and Computation (show other bugs)
: Trunk
: All All
P4 enhancement with 5 votes (vote)
: mozilla6
Assigned To: David Baron :dbaron: ⌚️UTC-8
: Jet Villegas (:jet)
Depends on: 943217 1310335
Blocks: 634764
  Show dependency treegraph
Reported: 2007-10-07 22:30 PDT by Jason Barnabe (np)
Modified: 2016-11-13 02:42 PST (History)
13 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---

patch (19.15 KB, patch)
2011-04-24 09:51 PDT, David Baron :dbaron: ⌚️UTC-8
bzbarsky: review+
mounir: feedback+
Details | Diff | Splinter Review
add missing break (764 bytes, patch)
2011-06-04 00:42 PDT, David Baron :dbaron: ⌚️UTC-8
bzbarsky: review+
Details | Diff | Splinter Review

Description User image Jason Barnabe (np) 2007-10-07 22:30:57 PDT
While domain, url, and url-prefix cover the majority of the cases you'd want to use -moz-document rules for, there are situations they can't cover adequately. For example, affecting URLs that end with a certain string ("/Special:RecentChanges") or URLs that have a changeable middle part ("").

A regular expression function would cover these remaining cases.
Comment 1 User image David Baron :dbaron: ⌚️UTC-8 2008-04-13 11:25:58 PDT
(See also discussion in bug 423985, although nothing particularly relevant, I suppose.)
Comment 2 User image Jason Barnabe (np) 2008-08-04 19:46:23 PDT
I will send $100 Canadian to anyone who can get this in for Firefox 3.1.
Comment 3 User image Evengard 2010-04-12 00:46:24 PDT
The problem is that Firefox doesn't have a direct regexp implementation, only a JSRegExp, but I can't find any way to access it from C++...
Comment 4 User image David Baron :dbaron: ⌚️UTC-8 2011-04-23 20:50:55 PDT is a patch for this that compiles, but I haven't yet tested it at all.
Comment 5 User image David Baron :dbaron: ⌚️UTC-8 2011-04-24 09:51:14 PDT
Created attachment 528008 [details] [diff] [review]
Comment 6 User image David Baron :dbaron: ⌚️UTC-8 2011-04-24 09:52:16 PDT
Comment on attachment 528008 [details] [diff] [review]

And requesting feedback from Mounir to make sure he's ok with this method moving (unchanged) from nsHTMLInputElement to nsContentUtils.
Comment 7 User image Boris Zbarsky [:bz] (still a bit busy) 2011-04-28 07:43:58 PDT
Comment on attachment 528008 [details] [diff] [review]

>+      // copy before we know it's valid

Please document why (ExpectSymbol messing with mToken, I assume), and r=me.
Comment 8 User image David Baron :dbaron: ⌚️UTC-8 2011-04-28 10:26:57 PDT
Comment 9 User image Evgueni Naverniouk 2011-04-28 10:33:30 PDT
I am SO excited to see this get implemented. It's going to bring so much extra power to userstyles! Thank you Mozilla.
Comment 10 User image Eric Shepherd [:sheppy] 2011-04-28 16:44:17 PDT
Documentation updated:

And mentioned on Firefox 6 for developers.
Comment 11 User image Mounir Lamouri (:mounir) 2011-04-29 11:34:25 PDT
Comment on attachment 528008 [details] [diff] [review]

I'm happy to see this code moving to nsContentUtils.
And I'm sorry that the feedback took so long. I'm abroad for the week for a community event and it's hard to get a good internet connectivity. Though I see the patch has been landed so it didn't block anything ;)
Comment 12 User image David Baron :dbaron: ⌚️UTC-8 2011-04-30 15:28:26 PDT
Added one additional test:
Comment 13 User image Jason Barnabe (np) 2011-06-03 19:52:09 PDT
It looks to me like you need to enclose the regexp in a single or double quote (unlike url, url-prefix, and domain). Just want to make sure that that was intended.

Also, missing a "break;" here?

diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp
--- a/layout/style/nsCSSRules.cpp
+++ b/layout/style/nsCSSRules.cpp
@@ -942,16 +942,18 @@ DocumentRule::List(FILE* out, PRInt32 aI
       case eURL:
       case eURLPrefix:
       case eDomain:
+      case eRegExp:
+        str.AppendLiteral("regexp(\"");
Comment 14 User image David Baron :dbaron: ⌚️UTC-8 2011-06-04 00:42:55 PDT
Created attachment 537322 [details] [diff] [review]
add missing break

I should add a general test for rule parse+serialize idempotence that would catch this...
Comment 15 User image David Baron :dbaron: ⌚️UTC-8 2011-06-04 00:49:08 PDT
Yes, requiring quotes was intended.
Comment 16 User image Boris Zbarsky [:bz] (still a bit busy) 2011-06-06 11:49:21 PDT
Comment on attachment 537322 [details] [diff] [review]
add missing break

Comment 17 User image David Baron :dbaron: ⌚️UTC-8 2011-06-12 20:21:13 PDT
Added missing break:
and added a test that would have caught if that were in the non-DEBUG function:

Note You need to log in before you can comment on or make changes to this bug.