瀏覽代碼

fix #1666 replace with %20

Shinsuke Sugaya 7 年之前
父節點
當前提交
255ca5ff7e

+ 18 - 8
src/main/java/org/codelibs/fess/ds/impl/GitBucketDataStoreImpl.java

@@ -119,7 +119,9 @@ public class GitBucketDataStoreImpl extends AbstractDataStoreImpl {
                 // branch is empty when git repository is empty.
                 if (StringUtil.isNotEmpty(branch)) {
                     final String refStr = getGitRef(rootURL, authToken, owner, name, branch);
-                    logger.info("Crawl " + owner + "/" + name);
+                    if (logger.isInfoEnabled()) {
+                        logger.info("Crawl " + owner + "/" + name);
+                    }
                     // crawl and store file contents recursively
                     crawlFileContents(
                             rootURL,
@@ -139,7 +141,9 @@ public class GitBucketDataStoreImpl extends AbstractDataStoreImpl {
                             });
                 }
 
-                logger.info("Crawl issues in " + owner + "/" + name);
+                if (logger.isInfoEnabled()) {
+                    logger.info("Crawl issues in " + owner + "/" + name);
+                }
                 // store issues
                 for (int issueId = 1; issueId <= issueCount + pullCount; issueId++) {
                     storeIssueById(rootURL, authToken, issueLabel, owner, name, new Integer(issueId), roleList, crawlingConfig, callback,
@@ -150,7 +154,9 @@ public class GitBucketDataStoreImpl extends AbstractDataStoreImpl {
                     }
                 }
 
-                logger.info("Crawl Wiki in " + owner + "/" + name);
+                if (logger.isInfoEnabled()) {
+                    logger.info("Crawl Wiki in " + owner + "/" + name);
+                }
                 // crawl Wiki
                 storeWikiContents(rootURL, authToken, wikiLabel, owner, name, roleList, crawlingConfig, callback, paramMap, scriptMap,
                         defaultDataMap, readInterval);
@@ -229,7 +235,9 @@ public class GitBucketDataStoreImpl extends AbstractDataStoreImpl {
             }
         } while (repoList.size() < totalCount);
 
-        logger.info("There exist " + repoList.size() + " repositories");
+        if (logger.isInfoEnabled()) {
+            logger.info("There exist " + repoList.size() + " repositories");
+        }
         return repoList;
     }
 
@@ -389,7 +397,6 @@ public class GitBucketDataStoreImpl extends AbstractDataStoreImpl {
         }
 
         for (final String page : pageList) {
-            // FIXME: URL encoding (e.g. page name that contains spaces)
             final String pageUrl = wikiUrl + "/contents/" + page + ".md";
             final String viewUrl = rootURL + owner + "/" + name + "/wiki/" + page;
 
@@ -399,7 +406,8 @@ public class GitBucketDataStoreImpl extends AbstractDataStoreImpl {
 
             final Map<String, Object> dataMap = new HashMap<>();
             dataMap.putAll(defaultDataMap);
-            dataMap.putAll(ComponentUtil.getDocumentHelper().processRequest(crawlingConfig, paramMap.get("crawlingInfoId"), pageUrl));
+            dataMap.putAll(ComponentUtil.getDocumentHelper().processRequest(crawlingConfig, paramMap.get("crawlingInfoId"),
+                    pageUrl.replace("+", "%20")));
 
             dataMap.put("url", viewUrl);
             dataMap.put("role", roleList);
@@ -408,7 +416,9 @@ public class GitBucketDataStoreImpl extends AbstractDataStoreImpl {
             // TODO scriptMap
 
             callback.store(paramMap, dataMap);
-            logger.info("Stored " + pageUrl);
+            if (logger.isDebugEnabled()) {
+                logger.debug("Stored " + pageUrl);
+            }
 
             if (readInterval > 0) {
                 sleep(readInterval);
@@ -453,7 +463,7 @@ public class GitBucketDataStoreImpl extends AbstractDataStoreImpl {
         }
     }
 
-    private String encode(final String rootURL, final String path, final String query) {
+    protected String encode(final String rootURL, final String path, final String query) {
         try {
             final URI rootURI = new URI(rootURL);
             final URI uri =

+ 42 - 0
src/test/java/org/codelibs/fess/ds/impl/GitBucketDataStoreImplTest.java

@@ -0,0 +1,42 @@
+/*
+ * Copyright 2012-2018 CodeLibs Project and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.codelibs.fess.ds.impl;
+
+import org.codelibs.fess.unit.UnitFessTestCase;
+
+public class GitBucketDataStoreImplTest extends UnitFessTestCase {
+    public GitBucketDataStoreImpl dataStore;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        dataStore = new GitBucketDataStoreImpl();
+    }
+
+    public void test_encode() {
+        String rootURL = "https://gitbucket.com/";
+        String path;
+        String query;
+
+        path = "api/v3/repos/";
+        query = "aaa=111";
+        assertEquals("https://gitbucket.com/api/v3/repos/?aaa=111", dataStore.encode(rootURL, path, query));
+
+        path = "api/v3/repos/AA BB";
+        query = "aaa=11 11";
+        assertEquals("https://gitbucket.com/api/v3/repos/AA%20BB?aaa=11%2011", dataStore.encode(rootURL, path, query));
+    }
+}