JavaChat / OakBot

A Java-based chat bot for Stackoverflow Chat
46 stars 32 forks source link

Fix login #40

Closed LunarWatcher closed 6 years ago

LunarWatcher commented 6 years ago

Why this exists

https://chat.stackoverflow.com/transcript/message/41645643#41645643

What happened

The fkey on the login page is 64 chars, but the one in chat is 32 chars. Meaning defining the length is a pain, since it isn't universal. The regex I added here is one I use in my project too, which simply does something stupid by parsing more of the HTML. It doesn't define a length, but it's more or less guaranteed to find the right tag as the pattern is the same in chat and across the SE network (meaning it's the same on SO, SE and MSE, both in chat and login).

Anyways, removing the length definition and increasing the amount of data necessary to match still leads to a single match, and this time it doesn't require the fkey to be a specific length. Meaning it can get the 32 char one from chat and the 64 char one from login. And it's mostly future-proof too.

And I did test this before I made the PR to make sure it works: and it does. At least for the time being.

codecov-io commented 6 years ago

Codecov Report

Merging #40 into master will increase coverage by 1.22%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #40      +/-   ##
==========================================
+ Coverage   53.09%   54.31%   +1.22%     
==========================================
  Files          73       73              
  Lines        3605     3605              
  Branches      607      607              
==========================================
+ Hits         1914     1958      +44     
+ Misses       1560     1512      -48     
- Partials      131      135       +4
Impacted Files Coverage Δ
src/main/java/oakbot/util/ChatUtils.java 75% <100%> (ø) :arrow_up:
...in/java/oakbot/command/javadoc/JavadocZipFile.java 76.8% <0%> (+0.79%) :arrow_up:
.../java/oakbot/command/javadoc/JavadocDaoCached.java 82.35% <0%> (+42.15%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 976da1d...e883287. Read the comment docs.

mangstadt commented 6 years ago

As you alluded to, since it's such a specific regex, I would rather not use it. For example, it doesn't work with: <input value="abc123" type="hidden" name="fkey">

Instead, I used jsoup to properly parse the HTML. It's a little overkill, but it's more robust overall. See: 04749d500a3483e3fec261d16851dc8a6b017106