[poppler] Branch 'xpdf303merge' - poppler/Link.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Mon Sep 5 12:03:33 PDT 2011


 poppler/Link.cc |   35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

New commits:
commit b655316706ec394fa6c8ad076d9d9d96ac8ed563
Author: Albert Astals Cid <aacid at kde.org>
Date:   Mon Sep 5 21:05:55 2011 +0200

    xpdf303: Rework LinkURI decoding

diff --git a/poppler/Link.cc b/poppler/Link.cc
index bdbba57..54ef698 100644
--- a/poppler/Link.cc
+++ b/poppler/Link.cc
@@ -542,28 +542,31 @@ LinkURI::LinkURI(Object *uriObj, GooString *baseURI) {
 
   uri = NULL;
   if (uriObj->isString()) {
-    uri2 = uriObj->getString()->copy();
-    if (baseURI && baseURI->getLength() > 0) {
-      n = strcspn(uri2->getCString(), "/:");
-      if (n == uri2->getLength() || uri2->getChar(n) == '/') {
+    uri2 = uriObj->getString();
+    n = (int)strcspn(uri2->getCString(), "/:");
+    if (n < uri2->getLength() && uri2->getChar(n) == ':') {
+      // "http:..." etc.
+      uri = uri2->copy();
+    } else if (!uri2->cmpN("www.", 4)) {
+      // "www.[...]" without the leading "http://"
+      uri = new GooString("http://");
+      uri->append(uri2);
+    } else {
+      // relative URI
+      if (baseURI) {
 	uri = baseURI->copy();
 	c = uri->getChar(uri->getLength() - 1);
-	if (c == '/' || c == '?') {
-	  if (uri2->getChar(0) == '/') {
-	    uri2->del(0);
-	  }
+	if (c != '/' && c != '?') {
+	  uri->append('/');
+	}
+	if (uri2->getChar(0) == '/') {
+	  uri->append(uri2->getCString() + 1, uri2->getLength() - 1);
 	} else {
-	  if (uri2->getChar(0) != '/') {
-	    uri->append('/');
-	  }
+	  uri->append(uri2);
 	}
-	uri->append(uri2);
-	delete uri2;
       } else {
-	uri = uri2;
+	uri = uri2->copy();
       }
-    } else {
-      uri = uri2;
     }
   } else {
     error(errSyntaxWarning, -1, "Illegal URI-type link");


More information about the poppler mailing list