Niedzielski has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/394473 )

Change subject: Chore: rename RESTBase HTTP modules
......................................................................

Chore: rename RESTBase HTTP modules

Move page-redirect to restbase-redirect and rename PageRedirect to
RESTBaseRedirect since it's not necessarily page-specific. Similarly,
move restbase-title-encoder to restbase-path-encoder and rename
reencodeRESTBaseTitlePath to reencodePathSegment.

Change-Id: I3ead170e3dbf38db221f987be7223f1d5b6be386
---
M src/common/http/page-http-client.ts
M src/common/http/page-summary-http-client.ts
A src/common/http/restbase-path-encoder.test.ts
R src/common/http/restbase-path-encoder.ts
R src/common/http/restbase-redirect.ts
D src/common/http/restbase-title-encoder.test.ts
6 files changed, 29 insertions(+), 32 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/marvin refs/changes/73/394473/1

diff --git a/src/common/http/page-http-client.ts 
b/src/common/http/page-http-client.ts
index c7c015e..9c0b9d4 100644
--- a/src/common/http/page-http-client.ts
+++ b/src/common/http/page-http-client.ts
@@ -8,16 +8,16 @@
 } from "../marshallers/page/page-unmarshaller";
 import { RESTBase } from "../marshallers/restbase";
 import HttpResponse from "./http-response";
-import { PageRedirect } from "./page-redirect";
+import { RESTBaseRedirect } from "./restbase-redirect";
 import { fetch } from "./fetch-with-redirect";
-import reencodeRESTBaseTitlePath from "./restbase-title-encoder";
+import reencodePathSegment from "./restbase-path-encoder";
 
 // 
https://en.wikipedia.org/api/rest_v1/#!/Mobile/get_page_mobile_sections_title_revision
 // https://en.wikipedia.org/api/rest_v1/#!/Page_content/get_page_random_format
 interface PageParams {
   titlePath: PageTitlePath;
   revision?: number;
-  redirect?: PageRedirect;
+  redirect?: RESTBaseRedirect;
   random?: undefined;
 }
 export type Params = PageParams | { random: true };
@@ -30,7 +30,7 @@
   const { titlePath, revision, redirect } = params;
   const revisionPath = revision === undefined ? "" : `/${revision}`;
   const redirectParam = redirect === undefined ? "" : `&redirect=${redirect}`;
-  return `${RESTBase.BASE_URL}/page/${endpoint}/${reencodeRESTBaseTitlePath(
+  return `${RESTBase.BASE_URL}/page/${endpoint}/${reencodePathSegment(
     titlePath
   )}${revisionPath}${redirectParam}`;
 }
diff --git a/src/common/http/page-summary-http-client.ts 
b/src/common/http/page-summary-http-client.ts
index 140fdc4..edba132 100644
--- a/src/common/http/page-summary-http-client.ts
+++ b/src/common/http/page-summary-http-client.ts
@@ -3,15 +3,15 @@
 import { RESTBase } from "../marshallers/restbase";
 import { unmarshalPageSummary } from 
"../marshallers/page-summary/page-summary-unmarshaller"; // eslint-disable-line 
max-len
 import HttpResponse from "./http-response";
-import { PageRedirect } from "./page-redirect";
+import { RESTBaseRedirect } from "./restbase-redirect";
 import { fetch } from "./fetch-with-redirect";
-import reencodeRESTBaseTitlePath from "./restbase-title-encoder";
+import reencodePathSegment from "./restbase-path-encoder";
 
 // https://en.wikipedia.org/api/rest_v1/#!/Page_content/get_page_summary_title
 // https://en.wikipedia.org/api/rest_v1/#!/Page_content/get_page_random_format
 interface PageParams {
   titlePath: PageTitlePath;
-  redirect?: PageRedirect;
+  redirect?: RESTBaseRedirect;
   random?: undefined;
 }
 export type Params = PageParams | { random: true };
@@ -23,7 +23,7 @@
 
   const { titlePath, redirect } = params;
   const redirectParam = redirect === undefined ? "" : `&redirect=${redirect}`;
-  return `${RESTBase.BASE_URL}/page/summary/${reencodeRESTBaseTitlePath(
+  return `${RESTBase.BASE_URL}/page/summary/${reencodePathSegment(
     titlePath
   )}${redirectParam}`;
 };
diff --git a/src/common/http/restbase-path-encoder.test.ts 
b/src/common/http/restbase-path-encoder.test.ts
new file mode 100644
index 0000000..e40a0f9
--- /dev/null
+++ b/src/common/http/restbase-path-encoder.test.ts
@@ -0,0 +1,14 @@
+import * as assert from "assert";
+import reencodePathSegment from "./restbase-path-encoder";
+
+describe("restbase-path-encoder", () => {
+  describe(".reencodePathSegment()", () => {
+    it("encodes slashes and nothing else", () => {
+      assert.deepStrictEqual(reencodePathSegment("path/path"), "path%2fpath");
+    });
+
+    it("doesn't reencode already encoded slashes", () => {
+      assert.deepStrictEqual(reencodePathSegment("%2f"), "%2f");
+    });
+  });
+});
diff --git a/src/common/http/restbase-title-encoder.ts 
b/src/common/http/restbase-path-encoder.ts
similarity index 82%
rename from src/common/http/restbase-title-encoder.ts
rename to src/common/http/restbase-path-encoder.ts
index 1269a29..d56014b 100644
--- a/src/common/http/restbase-title-encoder.ts
+++ b/src/common/http/restbase-path-encoder.ts
@@ -1,8 +1,8 @@
-import { PageTitlePath } from "../models/page/title";
-
-export default function reencodeRESTBaseTitlePath(
-  title: PageTitlePath
-): PageTitlePath {
+/**
+ * @param {!string} segment URL-encoded path segment.
+ * @return URL-encoded path segment with slashes encoded.
+ */
+export default function reencodePathSegment(segment: string): string {
   // RESTBase doesn't understand page titles with slashes in them. An encoded
   // path cannot be blindly reencoded with encodeURIComponent() because that 
may
   // doubly encode characters which gives different meaning when its unencoded
@@ -25,5 +25,5 @@
   // - https://en.wikipedia.org/wiki/?
   // - https://en.wikipedia.org/api/rest_v1/page/mobile-sections//
   // - https://en.wikipedia.org/api/rest_v1/page/mobile-sections/?
-  return title.replace("/", "%2f");
+  return segment.replace("/", "%2f");
 }
diff --git a/src/common/http/page-redirect.ts 
b/src/common/http/restbase-redirect.ts
similarity index 92%
rename from src/common/http/page-redirect.ts
rename to src/common/http/restbase-redirect.ts
index 45b48ba..f57fcfb 100644
--- a/src/common/http/page-redirect.ts
+++ b/src/common/http/restbase-redirect.ts
@@ -10,4 +10,4 @@
  * [redirect pages]: http://localhost:3000/wiki/Help:Redirects
  * [spec bug]: https://github.com/whatwg/fetch/issues/204
  */
-export type PageRedirect = boolean;
+export type RESTBaseRedirect = boolean;
diff --git a/src/common/http/restbase-title-encoder.test.ts 
b/src/common/http/restbase-title-encoder.test.ts
deleted file mode 100644
index ae6938a..0000000
--- a/src/common/http/restbase-title-encoder.test.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import * as assert from "assert";
-import reencodeRESTBaseTitlePath from "./restbase-title-encoder";
-
-describe("restbase-title-encoder", () => {
-  describe(".reencodeRESTBaseTitlePath()", () => {
-    it("encodes slashes and nothing else", () => {
-      assert.deepStrictEqual(
-        reencodeRESTBaseTitlePath("path/path"),
-        "path%2fpath"
-      );
-    });
-
-    it("doesn't reencode already encoded slashes", () => {
-      assert.deepStrictEqual(reencodeRESTBaseTitlePath("%2f"), "%2f");
-    });
-  });
-});

-- 
To view, visit https://gerrit.wikimedia.org/r/394473
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3ead170e3dbf38db221f987be7223f1d5b6be386
Gerrit-PatchSet: 1
Gerrit-Project: marvin
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>
Gerrit-Reviewer: Sniedzielski <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to