wikimedia / mediawiki-title

mediawiki title normalization library
8 stars 12 forks source link

Title.newFromText should not throw exception for invalid title #37

Open santhoshtr opened 6 years ago

santhoshtr commented 6 years ago

The mw.Title in mediawiki core has the following behavior for invalid titles: Use #newFromText to use the logic directly and get null for invalid titles which is easier to work with.

But this library throws errors for invalid characters. Would it be a nice idea to make the behavior consistent with mediawiki core?

cscott commented 5 years ago

In Parsoid we use a wrapper for these cases:

try {
  return Title.newFromText(...args);
} catch (e) {
  return null;
}

This is a little more robust if you assert that the caught error is instanceof TitleError (see PR #42).