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

Wrong use of "String:indexOf" #21

Open
UlliBien opened this issue Apr 1, 2017 · 1 comment
Open

Wrong use of "String:indexOf" #21

UlliBien opened this issue Apr 1, 2017 · 1 comment

Comments

@UlliBien
Copy link

UlliBien commented Apr 1, 2017

I tested your program. Works very fine! But there is a little bug in the code.

This is the code used for detecting a search request:
if (request.indexOf('M-SEARCH') > 0) {
if (request.indexOf("urn:Belkin:device:**") > 0) {
...

The first indexOf gives a warning "To many chars in char constant". It is compiled to "indexOf('M')". Replacing it with indexOf("M-SEARCH") does not work, because "M-SEARCH" is at position 0. indexOf() returns -1 if a string is not found!

Replace the code by
if (request.indexOf('M-SEARCH') > -1) {
if (request.indexOf("urn:Belkin:device:**") > -1) {
...

or

if (request.indexOf('M-SEARCH') == 0) {
if (request.indexOf("urn:Belkin:device:**") > -1) {
...

@szakharchenko
Copy link

szakharchenko commented Apr 12, 2017

You just want to use double quotes instead of single quotes, and startsWith would better describe the intent.

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

2 participants