Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From this Wikipedia article it looks like the scheme, host and port have to be the same to satisfy the same origin policy.</p> <p><a href="http://en.wikipedia.org/wiki/Same_origin_policy" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Same_origin_policy</a></p> <pre><code>require 'uri' class SameOrigin def self.test(str1, str2) uri1 = URI.parse(str1) uri2 = URI.parse(str2) uri1.scheme == uri2.scheme &amp;&amp; uri1.host == uri2.host &amp;&amp; uri1.port == uri2.port end end SameOrigin.test "http://google.com", "http://google.com" # =&gt; true SameOrigin.test "http://google.com:80", "http://google.com" # =&gt; true SameOrigin.test "http://google.com", "http://www.google.com" # =&gt; false SameOrigin.test "https://google.com", "http://google.com" # =&gt; false </code></pre> <p>If you use the <a href="https://github.com/pauldix/domainatrix" rel="nofollow noreferrer">Domainatrix</a> library I found you could change the code to something like this for your test, but it runs a little slow for me. Another option would be to use this RegEx to find the domain of a url. The RegEx is faster but may not work in all cases. I found the RegEx here, btw.</p> <p><a href="https://stackoverflow.com/a/983558/107797">Remove subdomain from string in ruby</a></p> <pre><code>require 'rubygems' require 'domainatrix' require 'uri' class SameOrigin def self.relaxed_test(str1, str2) d1 = Domainatrix.parse(str1) d1 = Domainatrix.parse(str2) uri1 = URI.parse(str1) uri2 = URI.parse(str2) uri1.scheme == uri2.scheme &amp;&amp; d1.domain == d1.domain &amp;&amp; d1.public_suffix == d1.public_suffix &amp;&amp; uri1.port == uri2.port end def self.relaxed_test2(str1, str2) uri1 = URI.parse(str1) uri2 = URI.parse(str2) re = /^(?:(?&gt;[a-z0-9-]*\.)+?|)([a-z0-9-]+\.(?&gt;[a-z]*(?&gt;\.[a-z]{2})?))$/i domain1 = uri1.host.gsub(re, '\1').strip domain2 = uri2.host.gsub(re, '\1').strip uri1.scheme == uri2.scheme &amp;&amp; domain1 == domain2 &amp;&amp; uri1.port == uri2.port end end SameOrigin.relaxed_test "http://google.com", "http://google.com" # =&gt; true SameOrigin.relaxed_test "http://google.com:80", "http://google.com" # =&gt; true SameOrigin.relaxed_test "http://google.com", "http://www.google.com" # =&gt; false SameOrigin.relaxed_test "https://google.com", "http://google.com" # =&gt; false SameOrigin.relaxed_test2 "http://google.com", "http://google.com" # =&gt; true SameOrigin.relaxed_test2 "http://google.com:80", "http://google.com" # =&gt; true SameOrigin.relaxed_test2 "http://google.com", "http://www.google.com" # =&gt; false SameOrigin.relaxed_test2 "https://google.com", "http://google.com" # =&gt; false </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload