Project

General

Profile

« Previous | Next » 

Revision 1dcdb672

Added by Katja Luther about 2 years ago

ref #9114: adapt parsing of fragment and add test

View differences:

cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/URI.java
112 112
                    if (url.getQuery() != null){
113 113
                        encodedUri = encodedUri.replace(url.getQuery(), UrlUtf8Coder.encode(url.getQuery()));
114 114
                    }
115
                    String[] fragmentElements =  uriString.split("#");
116
                    
117
                    for (int i = 1; i < fragmentElements.length; ++i){
118
                    	String fragmentElement = fragmentElements[i];
119
                        if(fragmentElement.contains("\\")){
115
                    String fragmentElement =  uriString.substring(uriString.indexOf("#")+1,uriString.length());
116
                    if(fragmentElement.contains("\\")){
120 117
                            //TODO needs discussion if backslash should be converted to slash instead, for now we keep it more strict
121
                            throw new URISyntaxException(uriString, "URI path must not contain backslash ('\')");
122
                        }
123
                        String replacement = UrlUtf8Coder.encode(fragmentElement);
124
                        encodedUri = encodedUri.replace(fragmentElement, replacement);
118
                    	throw new URISyntaxException(uriString, "URI path must not contain backslash ('\')");
125 119
                    }
126
                    
120
                    String replacement = UrlUtf8Coder.encode(fragmentElement);
121
                    encodedUri = encodedUri.replace(fragmentElement, replacement);
127 122

  
128 123
                    url = new URL(encodedUri);
129 124

  
cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/UriTest.java
41 41
        }
42 42

  
43 43
    }
44
    
45
    @Test
46
    public void testFragment() {
47
        try {
48
            //see example in #9111
49
            URI uri = new URI("https://max:muster@www.example.com:8080/index.html?p1=A&p2=B#ressource");
50
            Assert.assertEquals(
51
                    "ressource",
52
                    uri.getFragment());
53

  
54
        } catch (URISyntaxException e) {
55
            Assert.fail("Parsing example URI should find fragment");
56
        }
57

  
58
        try {
59
            //see example in #9111
60
            URI uri = new URI("http:\\www.fail.de");
61
            Assert.fail("Using backslash in URI instead of slash should fail");
62
        } catch (URISyntaxException e) {
63
            //OK
64
        }
65

  
66
    }
44 67

  
45 68
}

Also available in: Unified diff