tractorcow-farm / silverstripe-fluent

Multi-language translate module for Silverstripe, without having to manage separate site trees.
BSD 3-Clause "New" or "Revised" License
93 stars 111 forks source link

Cannot fetch translations when table names include spaces. #764

Open GuySartorelli opened 2 years ago

GuySartorelli commented 2 years ago

Originally opened as Silverstripe/silverstripe-framework#10259 by @marimchen

Can you please add some kind of warning message or an red error-message in dev/build for classes which have a blank at the beginning of their name e.g " MyTable" or "My Table". It's hard to see in the database itself and it causes real bad behaviour for popular modules like silverstripe-fluent from tractorcow.

Thank you very much, kind regards

Per discussion in the original issue, spaces in table names are valid in SQL and so should be allowed by the fluent module (as opposed to presenting an error or warning as suggested above).

This is now being raised here because as per @marimchen:

It was overlooked because everything worked as it should, except of fluent, which couldn't handle fetching the translations correct because of that.

It sounds like table names just aren't being quoted correctly somewhere - hopefully @marimchen can provide more specifics about exactly how this was found and how the problem presented.

tractorcow commented 2 years ago

you could probably look at some of the preg_match in code and change the \w to include spaces.

e.g.

// FluentExtension.php
if (preg_match('/"(?<table>[\w\\\\]+)"\."(?<field>\w+)"/i', $sql, $matches)) {

Do you want to submit a patch for your case and test with your db with spaces?

Make sure not to try matching fields with spaces; I don't know if silverstripe supports columns with whitespace in them.