Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fixed generation of bbcode for uppercased tags #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

frastel
Copy link
Contributor

@frastel frastel commented Feb 13, 2017

This PR is actually based on my other cleanup PR. This PR makes only sense after the cleanup PR has been merged.

I found two issues:

  • when uppercased tags were used and the text was invalid than the code was not able to re-build the original code. [URL=INVALID]foo[/URL] was generated to [url=invalid]foo[/url].
  • when options were enabled but the tag itself had no option and the text was invalid than the code added an empty =. So [URL foo=bar]INVALID[/URL] was generated to [url= foo=bar]INVALID[/url].

I am not quite sure if the change in ElementNode::getAsBBCode for the empty = is the best solution. Therefore this PR is still WIP. Any feedback appreciated!

@DaSourcerer
Copy link
Contributor

Ugh! Can you remove 2bd7dc7 and force push? This is extremely hard to assess correctly as-is. Appreciate your effort, though!

* @param string $code
*
* @dataProvider textCodeProviderWithInvalidCode
* @group debug
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???

@frastel frastel force-pushed the fix/tag-normalization branch 2 times, most recently from dc30728 to 6005b2c Compare February 13, 2017 20:41
@frastel
Copy link
Contributor Author

frastel commented Feb 13, 2017

@DaSourcerer Sure no problem. Branch is cleaned.

require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Parser.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'UppercasedCodeDefinitionSet.php';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange, I needed this for Travis. It worked fine without it on my local setup.

@shmax
Copy link
Contributor

shmax commented Feb 13, 2017

when uppercased tags were used and the text was invalid than the code was not able to re-build the original code. [URL=INVALID]foo[/URL] was generated to [url=invalid]foo[/url].

Can you elaborate a little on what problems that causes?

@DaSourcerer
Copy link
Contributor

@shmax I think, he doesn't experience any actual problems safe for the parts of the input that could not be parsed as tags being forcibly turned all-lowercase. I am actually in support of this, but find this implementation not very convincing. There has to be a better way than to keep tagname and the original token when one is directly derived from the other. Could be this is a bit of a hint some refactoring may be in order? After all, we've got ElementNode.getTagName() and ElementNode.getCodeDefinition().getTagName(). Latter one is already guaranteed to be lowercase. No easy win, though ...

Oh, and while we're at it: Do we want to support tagnames with multibyte characters in them?

@shmax
Copy link
Contributor

shmax commented Feb 13, 2017

There has to be a better way than to keep tagname and the original

That was my thought as well, particularly as he's doing some run-time string operations that weren't there before, even with the double storage.

foreach($this->attribute as $key => $value){
if($key == $this->tagName){
foreach ($this->attribute as $key => $value) {
if ($this->normalize($key) == $this->normalize($this->originalTagName)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you check against $this->tagName? It's already been normalized by this point, hasn't it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what about strcasecmp()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was worried about this change by myself too. I'll go for the strcasecmp approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@frastel
Copy link
Contributor Author

frastel commented Feb 14, 2017

@shmax

Can you elaborate a little on what problems that causes?

I didn't expected any text modification when an invalid code is given. For my current project the strtolower modification is not accetable.

@DaSourcerer The changes might not be very convincing however I didn't want to introduce too many changes at once in one of my first contributions to this project and thus I tried to not break the current structure.

@Kubo2
Copy link
Contributor

Kubo2 commented Feb 14, 2017

@DaSourcerer:

Do we want to support tagnames with multibyte characters in them?

Just curious: is it very difficult to implement compared to the current implementation?

@DaSourcerer
Copy link
Contributor

@frastel: As I said, this may be a hint some refactoring were in order. I understand your reluctance to introduce possibly code-breaking changes, but I just feel there is a better solution. Btw: That would be a shortcoming on our side, not yours ;)

@Kubo2: It is so-so. We would introduce a hard dependency on the mb extensions (which is probably less probelmatic than I may make it sound like here). We also use the normalized (i.e. lowercased) tag names for various lookups. I am not quite sure how array keys with mb-characters in them behave. Worst scenario: We would lose all 𝓞(1) lookups and have them replaced with 𝓞(n). Worth it? I really don't know ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants