Skip to content

Commit 1a906fd

Browse files
Issue-813: Handle span class names with version numbers appended (#862)
1 parent d081380 commit 1a906fd

File tree

5 files changed

+31
-19
lines changed

5 files changed

+31
-19
lines changed

composer-team-city.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
"wpackagist-plugin/plugin-activation-status": "@stable",
7373
"wpackagist-plugin/really-simple-ssl": "@stable",
7474
"wpackagist-plugin/redis-cache": "@stable",
75-
"wpackagist-plugin/sqlite-database-integration": "@stable",
7675
"wpackagist-plugin/tinymce-advanced": "@stable",
7776
"wpackagist-plugin/unconfirmed": "@stable",
7877
"wpackagist-plugin/wordfence": "@stable",

composer_team_city_links.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ do
5050
ln -sfn "${f}" "${thisDir}/wordpress-develop/src/${fn}"
5151
done
5252

53-
# copy the SQLite db file
54-
FILE="${thisDir}/wordpress-develop/src/wp-content/plugins/sqlite-database-integration/db.copy"
55-
if [[ -f "$FILE" ]]; then
56-
cp "${FILE}" "${thisDir}/wordpress-develop/src/wp-content/db.php"
57-
fi
58-
59-
6053
# copy additional default localizations
6154
mkdir -p "${thisDir}/wordpress-develop/src/wp-content/languages"
6255
FILES="${thisDir}/localizations/wordpress-base/*.mo"

resources/wp-tests-config.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
/* Path to the WordPress codebase you'd like to test. Add a forward slash in the end. */
44
define('ABSPATH', dirname(__DIR__) . '/wordpress-develop/src/');
55

6-
define('DB_DIR', dirname(__DIR__) . '/sqlite_db');
7-
if (!is_dir(DB_DIR))
8-
mkdir(DB_DIR, 0777, true);
9-
106
/*
117
* Path to the theme to test with.
128
*
@@ -42,9 +38,9 @@
4238
*/
4339

4440
define('DB_NAME', 'wp_webonary_test');
45-
define('DB_USER', getenv('BITBUCKET_MYSQL_USER'));
46-
define('DB_PASSWORD', getenv('BITBUCKET_MYSQL_PASSWORD'));
47-
define('DB_HOST', getenv('BITBUCKET_MYSQL_SERVER'));
41+
define('DB_USER', 'webonary');
42+
define('DB_PASSWORD', getenv('MARIADB_PASSWORD'));
43+
define('DB_HOST', 'localhost');
4844
define('DB_CHARSET', 'utf8mb4');
4945
define('DB_COLLATE', 'utf8mb4_unicode_ci');
5046

webonary-cloud-api/lambda/postEntry.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* @apiParam (Post Body) {String} body.mainheadword.lang ISO language code for the head word
2626
* @apiParam (Post Body) {String} body.mainheadword.value ISO head word
2727
* @apiParam (Post Body) {Object} body.audio Audio associated with the entry
28-
* @apiParam (Post Body) {String} body.audio.fileClass Css class for the audio
28+
* @apiParam (Post Body) {String} body.audio.fileClass CSS class for the audio
2929
* @apiParam (Post Body) {String} body.audio.id Unique id for audio file
3030
* @apiParam (Post Body) {String} body.audio.src Relative file path to the audio
3131
* @apiParam (Post Body) {Object[]} body.pictures Images associated with the entry
@@ -99,7 +99,7 @@
9999
* HTTP/1.1 500 Internal Server Error
100100
* {
101101
* "errorType": "SyntaxError",
102-
* "errorMessage": "Unexpected token } in JSON at position 243"
102+
* "errorMessage": "Unexpected token { in JSON at position 243"
103103
* }
104104
*/
105105

@@ -247,7 +247,7 @@ const getLangTexts = (xhtml: string) => {
247247
const searchTexts: string[] = [];
248248

249249
// eslint-disable-next-line array-callback-return
250-
$('span[lang]').each((index, elem) => {
250+
$('span[lang]').each((_index, elem) => {
251251
const lang = $(elem).attr('lang');
252252
const text = $(elem).text();
253253
if (!lang || !text) {
@@ -330,6 +330,22 @@ export const transformToEntry = ({
330330
};
331331
};
332332

333+
/**
334+
* This is to remove the version numbers FLEx is now appending to the class name of some span tags.
335+
*
336+
* @param postedEntry
337+
*/
338+
const fixSpanClassVersions = (postedEntry: any) => {
339+
340+
if (!postedEntry.displayXhtml)
341+
return;
342+
343+
// remove the version numbers from the span classes before processing
344+
const regex = /<span class="([^"\s]+?)-\d+"/g;
345+
const subst = `<span class="$1"`;
346+
postedEntry.displayXhtml = postedEntry.displayXhtml.replace(regex, subst);
347+
};
348+
333349
export async function upsertEntries(
334350
postedEntries: Array<any>,
335351
isReversal: boolean,
@@ -338,7 +354,11 @@ export async function upsertEntries(
338354
) {
339355
const updatedAt = new Date();
340356
const transformEntryFunction = isReversal ? transformToReversalEntry : transformToEntry;
357+
341358
const entries = postedEntries.map((postedEntry) => {
359+
360+
fixSpanClassVersions(postedEntry);
361+
342362
const entry = transformEntryFunction({ postedEntry, dictionaryId });
343363
entry.updatedAt = updatedAt;
344364
entry.updatedBy = username;

webonary-cloud-api/tools/flexXhtmlParser.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ export class FlexXhtmlParser {
2424
public parsedEntries: Entry[];
2525

2626
public constructor(toBeParsed: string, options: Partial<Options> = {}) {
27-
this.toBeParsed = toBeParsed;
27+
28+
// remove the version numbers from the span classes before parsing
29+
const regex = /<span class="([^"\s]+?)-\d+"/g;
30+
const subst = `<span class="$1"`;
31+
this.toBeParsed = toBeParsed.replace(regex, subst);
2832

2933
this.options = Object.assign(options);
3034

0 commit comments

Comments
 (0)