Uploaded image for project: 'Droids'
  1. Droids
  2. DROIDS-115

LinkExtractor getURI(String target) does not resolve correctly when baseUri is provided

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 0.2.0
    • core
    • None

    Description

      the getURI() Method won't resolve the URL correctly if a baseUri is provided without the trailing slash and the relative url to be resolved does not start with "/". Under that circumstances it will resolve to: http://example.comRelativeUrl.

      edit: previous patch did solve the problem only partially.

      Modified methods (whole class attached):

      public LinkExtractor(LinkTask base, Map<String, String> elements)

      { super(); this.base = base; this.elements = elements; this.setBaseUri(base.getURI()); }

      @Override
      public void startElement(String uri, String loc, String raw, Attributes att) throws SAXException {
      if (checkBase && BASE_ELEMENT.equalsIgnoreCase(loc) && att.getValue(BASE_ATTRIBUTE) != null) {
      try

      { setBaseUri(new URI(att.getValue(BASE_ATTRIBUTE))); log.debug("Found base URI: " + baseUri); checkBase = false; }

      catch (URISyntaxException e)

      { log.debug("Base URI not valid: " + att.getValue(BASE_ATTRIBUTE)); }

      }

      Iterator<String> it = elements.keySet().iterator();
      String elem, linkAtt;
      while (it.hasNext()) {
      elem = it.next();
      linkAtt = elements.get(elem);
      if (elem.equalsIgnoreCase(loc) && att.getValue(linkAtt) != null) {
      link = getURI(att.getValue(linkAtt));
      log.debug("Found element: " + elem + " with link: " + link);
      if (link != null)

      { addOutlinkURI(link.toString()); link = null; anchorText = new StringBuilder(); }

      }
      }
      }

      public void setBaseUri(URI baseUri) {
      if (baseUri.toString().endsWith(baseUri.getHost())) {
      try

      { this.baseUri = new URI(baseUri.toString() + "/"); }

      catch (URISyntaxException e)

      { log.error("could not fix base URI", e); }

      } else

      { this.baseUri = baseUri; }

      }

      Attachments

        1. LinkExtractor.java
          7 kB
          Paul Rogalinski

        Activity

          People

            Unassigned Unassigned
            pulsar256 Paul Rogalinski
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: