Revision: 5680
Author:   [email protected]
Date:     Mon Apr 28 22:53:26 2014 UTC
Log:      Implement <a>.pathname.
https://codereview.appspot.com/99830043

The value is the policy-rewritten URI, which may be inappropriate, but
it is at least a string value (and consistent with other properties).

Fixes <https://code.google.com/p/google-caja/issues/detail?id=1898>.

[email protected]

http://code.google.com/p/google-caja/source/detail?r=5680

Modified:
 /trunk/src/com/google/caja/plugin/domado.js
 /trunk/tests/com/google/caja/plugin/test-domado-dom-guest.html

=======================================
--- /trunk/src/com/google/caja/plugin/domado.js Mon Mar 17 19:47:30 2014 UTC
+++ /trunk/src/com/google/caja/plugin/domado.js Mon Apr 28 22:53:26 2014 UTC
@@ -4607,13 +4607,16 @@
       defineElement({
         domClass: 'HTMLAnchorElement',
         properties: function() { return {
+ // TODO(kpreid): Implement all components-of-the-URL properties in
+          // a generic and consistently-virtualized way.
           hash: PT.filter(
             false,
             function (value) { return unsuffix(value, idSuffix, value); },
             false,
             // TODO(felix8a): add suffix if href is self
             identity),
-          href: NP_UriValuedProperty('a', 'href')
+          href: NP_UriValuedProperty('a', 'href'),
+          pathname: PT.ROView(String)
         }; }
       });

=======================================
--- /trunk/tests/com/google/caja/plugin/test-domado-dom-guest.html Mon Mar 17 19:47:30 2014 UTC +++ /trunk/tests/com/google/caja/plugin/test-domado-dom-guest.html Mon Apr 28 22:53:26 2014 UTC
@@ -3221,11 +3221,11 @@
   });
 </script>

-<div class="testcontainer" id="testHash">
+<div class="testcontainer" id="testAnchorHash">
   <a id='test-hash' href="#foo">test a.hash and hash in a.href</a>
 </div>
 <script type="text/javascript">
-  jsunitRegister('testHash', function testHash() {
+  jsunitRegister('testAnchorHash', function testHash() {
     var a = document.getElementById('test-hash');

     assertEquals('#foo', a.hash);
@@ -3239,6 +3239,33 @@
     assertEquals(window.location + '#bar', a.getAttribute('href'));
     assertEquals(window.location + '#bar', a.href);

+    pass();
+  });
+</script>
+
+<div class="testcontainer" id="testAnchorPathname">
+  <a id="testAnchorPathname-a" href="http://example.invalid/path?query";>
+    testAnchorPathname
+  </a>
+</div>
+<script type="text/javascript">
+  jsunitRegister('testAnchorPathname', function testHash() {
+    var a = document.getElementById('testAnchorPathname-a');
+
+    // The path of the output of the URI rewriter is "/".
+ // Seeing the rewritten URI is not actually desirable, but is consistent
+    // with other behaviors. TODO(kpreid): Look into storing the original
+    // URI.
+    assertEquals('/', a.pathname);
+
+ // Currently do not support modifying a URL since the URI policy rewrite
+    // is not reversible
+    expectFailure(function() {
+      a.pathname = '1';
+    }, 'Assignment fails', function(e) {
+      return e.name === 'TypeError';
+    });
+
     pass();
   });
 </script>

--

--- You received this message because you are subscribed to the Google Groups "Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to