[LON-CAPA-cvs] cvs: loncom /xml londefdef.pm scripttag.pm

raeburn raeburn at source.lon-capa.org
Mon Sep 30 09:44:17 EDT 2013


raeburn		Mon Sep 30 13:44:17 2013 EDT

  Modified files:              
    /loncom/xml	londefdef.pm scripttag.pm 
  Log:
  - Access to dependencies/links in HTML files uploaded directly to a course,
    where dependency or linked item was also uploaded directly to the same 
    course.
    - Fix regexp used to identify items referenced in javascript object in text
     within <script></script>.
    - .js files in src attribute of <script> tag still retrieved, even if
     (type ="text/javascript" is missing) i.e., not valid xhtml.
  
  
-------------- next part --------------
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.447 loncom/xml/londefdef.pm:1.448
--- loncom/xml/londefdef.pm:1.447	Thu Sep 26 22:03:36 2013
+++ loncom/xml/londefdef.pm	Mon Sep 30 13:44:16 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.447 2013/09/26 22:03:36 raeburn Exp $
+# $Id: londefdef.pm,v 1.448 2013/09/30 13:44:16 raeburn Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -1732,7 +1732,7 @@
                             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                             if ($linkurl =~ m{^([^/]|/uploaded/$cdom/$cnum/docs/)}) {
-                                my $cleanhref = &Apache::londefdef::clean_docs_httpref($linkurl,$url,$cdom,$cnum);
+                                my $cleanhref = &clean_docs_httpref($linkurl,$url,$cdom,$cnum);
                                 if ($cleanhref) {
                                     &Apache::lonxml::extlink($cleanhref);
                                 }
@@ -3619,20 +3619,20 @@
                 } else {
                     $currentstring = $token->[4];
                 }
-                if (($url !~ m{^https?://}) && ($env{'request.course.id'})) {
-                    my $docuri = &Apache::lonnet::hreflocation('',$env{'request.filename'});
-                    my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
-                    my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
-                    if ($url =~ m{^([^/]|/uploaded/)}) {
-                        my $cleanhref = &Apache::londefdef::clean_docs_httpref($url,$docuri,$cdom,$cnum);
-                        if ($cleanhref) {
-                            &Apache::lonxml::extlink($cleanhref);
-                        }
-                    } elsif (($url =~ m{/res/$LONCAPA::domain_re/}) && ($docuri =~ m{^\Q/uploaded/$cdom/$cnum/docs/\E})) {
-                        if (!&Apache::lonnet::allowed('bre',$url)) {
-                            if (&Apache::lonnet::is_on_map($url)) {
-                                &Apache::lonxml::extlink($url);
-                            }
+            }
+            if (($url !~ m{^https?://}) && ($env{'request.course.id'})) {
+                my $docuri = &Apache::lonnet::hreflocation('',$env{'request.filename'});
+                my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+                my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+                if ($url =~ m{^([^/]|/uploaded/)}) {
+                    my $cleanhref = &clean_docs_httpref($url,$docuri,$cdom,$cnum);
+                    if ($cleanhref) {
+                        &Apache::lonxml::extlink($cleanhref);
+                    }
+                } elsif (($url =~ m{/res/$LONCAPA::domain_re/}) && ($docuri =~ m{^\Q/uploaded/$cdom/$cnum/docs/\E})) {
+                    if (!&Apache::lonnet::allowed('bre',$url)) {
+                        if (&Apache::lonnet::is_on_map($url)) {
+                            &Apache::lonxml::extlink($url);
                         }
                     }
                 }
@@ -4612,8 +4612,17 @@
                 return $cleanhref;
             }
         } else {
-            (my $path,$fname) = ($href =~ m{^(.+)/([^/]*)$});
-            $hrefpath = $relpath.$path;
+            if ($href =~ m{/}) {  
+                (my $path,$fname) = ($href =~ m{^(.*)/([^/]*)$});
+                $hrefpath = $relpath.$path;
+                if ($path eq '') {
+                    $hrefpath =~ s{/$}{};
+                }
+            } else {
+                $fname = $href;
+                $hrefpath = $relpath;
+                $hrefpath =~ s{/$}{};
+            }
         }
         if ($fname ne '') {
             my $cleanrelpath;
@@ -4625,11 +4634,10 @@
                     $cleanrelpath .= $dir.'/';
                 }
             }
-            $cleanrelpath =~ s{/$}{};
             if ($cleanrelpath ne '') {
-                $cleanhref = $prefix.'/'.$cleanrelpath.'/'.$fname;
+                $cleanhref = $prefix.$cleanrelpath.$fname;
             } else {
-                $cleanhref = $prefix.'/'.$fname;
+                $cleanhref = $prefix.$fname;
             }
         }
     }
Index: loncom/xml/scripttag.pm
diff -u loncom/xml/scripttag.pm:1.167 loncom/xml/scripttag.pm:1.168
--- loncom/xml/scripttag.pm:1.167	Thu Sep 26 22:03:36 2013
+++ loncom/xml/scripttag.pm	Mon Sep 30 13:44:16 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # <script> definiton
 #
-# $Id: scripttag.pm,v 1.167 2013/09/26 22:03:36 raeburn Exp $
+# $Id: scripttag.pm,v 1.168 2013/09/30 13:44:16 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -129,29 +129,31 @@
       if ($target ne "meta" && $target ne 'tex' && $target ne 'answer') {
 	  $result = $token->[4];
 	  $result.=$bodytext;
-          if ($type eq "text/javascript") {
-              my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
-              my $url=&Apache::lonnet::hreflocation('',$env{'request.filename'});
-              my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
-              my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
-              if ($src =~ /\.js$/) {
-                  if ($src !~ m{^(/|https?://)}) {
-                      my $cleanhref = &Apache::londefdef::clean_docs_httpref($src,$url,$cdom,$cnum);
-                      if ($cleanhref) {
-                          &Apache::lonxml::extlink($cleanhref);
-                      }
+          my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
+          my $url=&Apache::lonnet::hreflocation('',$env{'request.filename'});
+          my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+          my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+          if ($src ne '') {
+              if ($src !~ m{^(/|https?://)}) {
+                  my $cleanhref = &Apache::londefdef::clean_docs_httpref($src,$url,$cdom,$cnum);
+                  if ($cleanhref) {
+                      &Apache::lonxml::extlink($cleanhref);
                   }
-              } elsif (($src eq '') && ($bodytext ne '')) {
-                  if ($url =~ m{^\Q/uploaded/$cdom/$cnum/docs/\E}) {
-                      if ($bodytext =~ m{\.set\w+(Src|Swf)\(["']}i) {
-                          my @srcs = split(/\.set/,$bodytext);
-                          if (@srcs > 1) {
-                              foreach my $item (@srcs) {
-                                  if ($item =~ m{^(?:FlashPlayerSwf|MediaSrc|XMPSrc|ConfigurationSrc|PosterImageSrc)\(['"])([^$1]+)$1\)}is) {
-                                      my $cleanhref = &Apache::londefdef::clean_docs_httpref($2,$url,$cdom,$cnum);
-                                      if ($cleanhref) {
-                                          &Apache::lonxml::extlink($cleanhref);
-                                      }
+              }
+          } elsif (($type eq 'text/javascript') && ($bodytext ne '')) {
+              if ($url =~ m{^\Q/uploaded/$cdom/$cnum/docs/\E}) {
+                  if ($bodytext =~ m{\.set\w+(Src|Swf)\(["']}i) {
+                      my @srcs = split(/\.set/,$bodytext);
+                      if (scalar(@srcs) > 1) {
+                          foreach my $item (@srcs) {
+                              if ($item =~ m{^(FlashPlayerSwf|MediaSrc|XMPSrc|ConfigurationSrc|PosterImageSrc)\((['"])(?:(?!\2).)+\2\)}is) {
+                                  my $srctype = $1;
+                                  my $quote = $2;
+                                  
+                                  my ($fname) = ($item =~ m{^\Q$srctype($quote\E([^$quote]+)\Q$quote)\E}); 
+                                  my $cleanhref = &Apache::londefdef::clean_docs_httpref($fname,$url,$cdom,$cnum);
+                                  if ($cleanhref) {
+                                      &Apache::lonxml::extlink($cleanhref);
                                   }
                               }
                           }


More information about the LON-CAPA-cvs mailing list