Skip to content

wp-migration.sh: table_prefix parsed as ';' breaks step-6 URL update #25

@khoipro

Description

@khoipro

Observed: [INFO] Database: khoipro (prefix: ;) — TABLE_PREFIX is being parsed as a literal semicolon.

Root cause

TABLE_PREFIX=$(grep '^\$table_prefix' "$SRC_PATH/wp-config.php" \
  | sed "s/.*'//; s/'.*//" || echo "wp_")

For a normal line $table_prefix = 'wp_';, the first sed s/.*'// is greedy — .*' matches the longest string ending in ', which is everything up through the closing quote. So output becomes ;. The second sed has nothing to match.

Effect

Step 6 (URL update) builds the query as SELECT option_value FROM ${TABLE_PREFIX}options ...;options. mysql errors silently (stderr suppressed), CURRENT_URL stays empty, the search-replace fallback also fails (uses the same prefix). User sees Updating site URL log line but the DB never changes.

Fix

Use awk -F"'" '/^\$table_prefix[[:space:]]*=/ {print $2; exit}'. Plus validate the result is non-empty and matches [A-Za-z0-9_]+ to avoid SQL injection in the step-6 queries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions