[MediaWiki-commits] [Gerrit] mediawiki...mobileapps[master]: Bring back anchorencode and locutus dependency

2017-08-04 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/369805 )

Change subject: Bring back anchorencode and locutus dependency
..


Bring back anchorencode and locutus dependency

This is in preparation for Iebf446c2. When using the action API
instead of mobileview redirects.tofragment is not encoded.
While this may be fine eventually, once Parsoid implements T152540.
It's a bit early for now. Once Parsoid also implements T152540
the usage of anchorencode can be removed and this commit could
be reverted.

FYI, this reverts some of the changes done earlier in I4a78ead3 and 
Ib774f286.

Bug: T103362
Change-Id: I7fc075d8626c07424662265226ad7f13d582ed7d
---
A lib/anchorencode.js
M package.json
A test/lib/anchorencode/anchorencode-test.js
3 files changed, 65 insertions(+), 0 deletions(-)

Approvals:
  jenkins-bot: Verified
  Mholloway: Looks good to me, but someone else must approve
  Jdlrobson: Looks good to me, approved



diff --git a/lib/anchorencode.js b/lib/anchorencode.js
new file mode 100644
index 000..bfe2c53
--- /dev/null
+++ b/lib/anchorencode.js
@@ -0,0 +1,23 @@
+'use strict';
+
+const urlencode = require('locutus/php/url/urlencode');
+
+/**
+ * Encodes an input string so that it can be used as an HTML anchor id
+ * (e.g. for a section in a page: ).
+ * See 
https://www.mediawiki.org/wiki/Manual:PAGENAMEE_encoding#Encodings_compared
+ * https://www.mediawiki.org/wiki/Special:Code/MediaWiki/16279
+ * core/include/parser/CoreParserFunctions.php
+ * https://phabricator.wikimedia.org/T9059
+ * https://gerrit.wikimedia.org/r/#/c/226032/
+ * @param {!string} input the input string (usually the heading text of a 
section heading)
+ * @return {!string} the sanitized version of the input string so it can be 
used as an anchor.
+ */
+function anchorencode(input) {
+const id = input.replace(/\s+/g, '_');
+return urlencode(id)
+.replace(/%3A/g, ':')
+.replace(/%/g, '.');
+}
+
+module.exports = anchorencode;
diff --git a/package.json b/package.json
index ace1ab6..6dbcb37 100644
--- a/package.json
+++ b/package.json
@@ -50,6 +50,7 @@
 "express": "^4.14.0",
 "js-yaml": "^3.7.0",
 "mediawiki-title": "^0.6.3",
+"locutus": "^2.0.5",
 "preq": "^0.5.1",
 "service-runner": "^2.2.5",
 "swagger-router": "^0.5.5",
diff --git a/test/lib/anchorencode/anchorencode-test.js 
b/test/lib/anchorencode/anchorencode-test.js
new file mode 100644
index 000..9c23c1c
--- /dev/null
+++ b/test/lib/anchorencode/anchorencode-test.js
@@ -0,0 +1,41 @@
+'use strict';
+
+const assert = require('../../utils/assert.js');
+const anchorencode = require('../../../lib/anchorencode');
+
+describe('lib:anchorencode', function() {
+
+this.timeout(2); // eslint-disable-line no-invalid-this
+
+it('anchorencode(empty) should return an empty string', () => {
+assert.deepEqual(anchorencode(''), '');
+});
+
+it('anchorencode("a") should return a', () => {
+assert.deepEqual(anchorencode('a'), 'a');
+});
+
+it('anchorencode("Z") should return Z', () => {
+assert.deepEqual(anchorencode('Z'), 'Z');
+});
+
+it('anchorencode("  Z  ") should return Z', () => {
+assert.deepEqual(anchorencode('  Z  '), 'Z');
+});
+
+it('anchorencode("a b c") should return a_b_c', () => {
+assert.deepEqual(anchorencode('a b c'), 'a_b_c');
+});
+
+it('anchorencode("a  b  c") should return a_b_c', () => {
+assert.deepEqual(anchorencode('a  b  c'), 'a_b_c');
+});
+
+it('anchorencode("!@#$%^&*()") should return 
21.40.23.24.25.5E.26.2A.28.29', () => {
+assert.deepEqual(anchorencode('!@#$%^&*()'), 
'21.40.23.24.25.5E.26.2A.28.29');
+});
+
+it('anchorencode(":") should not be converted', () => {
+assert.deepEqual(anchorencode(':'), ':');
+});
+});

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I7fc075d8626c07424662265226ad7f13d582ed7d
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: BearND 
Gerrit-Reviewer: BearND 
Gerrit-Reviewer: Dbrant 
Gerrit-Reviewer: Fjalapeno 
Gerrit-Reviewer: GWicke 
Gerrit-Reviewer: Jdlrobson 
Gerrit-Reviewer: Jhernandez 
Gerrit-Reviewer: Mholloway 
Gerrit-Reviewer: Mhurd 
Gerrit-Reviewer: Mobrovac 
Gerrit-Reviewer: Niedzielski 
Gerrit-Reviewer: Ppchelko 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org

[MediaWiki-commits] [Gerrit] mediawiki...mobileapps[master]: Bring back anchorencode and locutus dependency

2017-08-02 Thread BearND (Code Review)
BearND has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/369805 )

Change subject: Bring back anchorencode and locutus dependency
..

Bring back anchorencode and locutus dependency

This is in preparation for Iebf446c2. When using the action API
instead of mobileview redirects.tofragment is not encoded.
While this may be fine eventually, once Parsoid implements T152540.
It's a bit early for now. Once Parsoid also implements T152540
the usage of anchorencode can be removed and this commit could
be reverted.

Bug: T103362
Change-Id: I7fc075d8626c07424662265226ad7f13d582ed7d
---
A lib/anchorencode.js
M package.json
A test/lib/anchorencode/anchorencode-test.js
3 files changed, 67 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps 
refs/changes/05/369805/1

diff --git a/lib/anchorencode.js b/lib/anchorencode.js
new file mode 100644
index 000..906f883
--- /dev/null
+++ b/lib/anchorencode.js
@@ -0,0 +1,25 @@
+'use strict';
+
+const urlencode = require('locutus/php/url/urlencode');
+
+/**
+ * Encodes an input string so that it can be used as an HTML anchor id
+ * (e.g. for a section in a page: ).
+ * See 
https://www.mediawiki.org/wiki/Manual:PAGENAMEE_encoding#Encodings_compared
+ * https://www.mediawiki.org/wiki/Special:Code/MediaWiki/16279
+ * core/include/parser/CoreParserFunctions.php
+ * https://phabricator.wikimedia.org/T9059
+ * https://gerrit.wikimedia.org/r/#/c/226032/
+ * @param {!string} input the input string (usually the heading text of a 
section heading)
+ * @return {!string} the sanitized version of the input string so it can be 
used as an anchor.
+ */
+function anchorencode(input) {
+const id = input.replace(/\s+/g, '_');
+return urlencode(id)
+.replace(/%3A/g, ':')
+.replace(/%/g, '.');
+}
+
+module.exports = {
+anchorencode
+};
diff --git a/package.json b/package.json
index ace1ab6..6dbcb37 100644
--- a/package.json
+++ b/package.json
@@ -50,6 +50,7 @@
 "express": "^4.14.0",
 "js-yaml": "^3.7.0",
 "mediawiki-title": "^0.6.3",
+"locutus": "^2.0.5",
 "preq": "^0.5.1",
 "service-runner": "^2.2.5",
 "swagger-router": "^0.5.5",
diff --git a/test/lib/anchorencode/anchorencode-test.js 
b/test/lib/anchorencode/anchorencode-test.js
new file mode 100644
index 000..b2eedd5
--- /dev/null
+++ b/test/lib/anchorencode/anchorencode-test.js
@@ -0,0 +1,41 @@
+'use strict';
+
+const assert = require('../../utils/assert.js');
+const a = require('../../../lib/anchorencode');
+
+describe('lib:anchorencode', function() {
+
+this.timeout(2); // eslint-disable-line no-invalid-this
+
+it('anchorencode(empty) should return an empty string', () => {
+assert.deepEqual(a.anchorencode(''), '');
+});
+
+it('anchorencode("a") should return a', () => {
+assert.deepEqual(a.anchorencode('a'), 'a');
+});
+
+it('anchorencode("Z") should return Z', () => {
+assert.deepEqual(a.anchorencode('Z'), 'Z');
+});
+
+it('anchorencode("  Z  ") should return Z', () => {
+assert.deepEqual(a.anchorencode('  Z  '), 'Z');
+});
+
+it('anchorencode("a b c") should return a_b_c', () => {
+assert.deepEqual(a.anchorencode('a b c'), 'a_b_c');
+});
+
+it('anchorencode("a  b  c") should return a_b_c', () => {
+assert.deepEqual(a.anchorencode('a  b  c'), 'a_b_c');
+});
+
+it('anchorencode("!@#$%^&*()") should return 
21.40.23.24.25.5E.26.2A.28.29', () => {
+assert.deepEqual(a.anchorencode('!@#$%^&*()'), 
'21.40.23.24.25.5E.26.2A.28.29');
+});
+
+it('anchorencode(":") should not be converted', () => {
+assert.deepEqual(a.anchorencode(':'), ':');
+});
+});

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7fc075d8626c07424662265226ad7f13d582ed7d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: BearND 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits