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

PKURLState causes 'w', 'ww', 'www' to be duplicated if at the end of the string being tokenized #27

Open
rayr007 opened this issue Jan 2, 2014 · 0 comments

Comments

@rayr007
Copy link

rayr007 commented Jan 2, 2014

What steps will reproduce the problem?

  1. Run DemoApp
  2. type a "w" in the string to tokenize on the Tokens tab
  3. click the Parse button

What is the expected output? What do you see instead?
There should be a single token "w". Instead, you get a single token "ww".

What version of the product are you using? On what operating system?
I used the latest code from git repository.

Please provide any additional information below.

I tracked this down to the methods in PKURLState.m
A: - (BOOL)parseWWWFromReader:(PKReader *)r
B: - (PKToken *)nextTokenFromReader:(PKReader *)r startingWith:(PKUniChar)cin tokenizer:(PKTokenizer *)t

  1. - B calls A to attempt to find a URL starting with www.
  2. - A does a read to look for more 'w' characters.
  3. - control returns to B and matched is NO so B does an unread to undo what A potentially read.
  4. - parsing continues

The problem is when the 'w' is at the end of the input string. Step 2 reads nothing so step 3 duplicates the w with the unread. If you type in "ww" and press parse, you get "wwww" out. This is also true regardless of what is before this token. "i am going to go talk to my w" will come out with tokens "i", "am", "going", "to", "talk", "to", "my", "ww".

Solution
I am thinking that - (BOOL)parseWWWFromReader:(PKReader *)r should do it's own cleanup (unread if necessary) before returning instead of the cleanup happening outside the method.

Work-around
You can avoid this bug by setting the tokenizer's URLState.allowsWWWPrefix to NO.

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

No branches or pull requests

1 participant