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

Bugfix of regex at FloatConvertor (version 2) #1944

Closed
wants to merge 1 commit into from
Closed

Bugfix of regex at FloatConvertor (version 2) #1944

wants to merge 1 commit into from

Conversation

i-Ching
Copy link
Contributor

@i-Ching i-Ching commented Nov 14, 2022

For passing your checks of #1942 A correct statement is: regex = r"[0-9]+(\.[0-9]+)?" Reference: https://www.flake8rules.com/rules/W605.html

I have no problem of correction without 'r' prefix directly at /site-packages/starlette/convertors.py of my computer. Having submitted last pull-request #1942, I realized to add a 'r' prefix to pass your tests.

For passing your checks of #1942
A correct statement is: regex = r"[0-9]+(\.[0-9]+)?"
Reference: https://www.flake8rules.com/rules/W605.html

I have no problem to corrected without 'r' prefix directly at /site-packages/starlette/convertors.py of my computer.
Having submitted last pull-request, I realized to add a 'r' prefix to pass your tests.
@i-Ching i-Ching closed this by deleting the head repository Nov 14, 2022
@i-Ching i-Ching reopened this Nov 14, 2022
@i-Ching
Copy link
Contributor Author

i-Ching commented Nov 14, 2022

Sorry I do not know that I deleted my fork of starlette to affect this pull request. Now I reopen it. This bugfix
regex = r"[0-9]+(\.[0-9]+)?" is for class FloatConvertor(Convertor) of site-packages/starlette/convertors.py

To avoid 500 Internal Server Error of http://localhost:8000/path/1-1 as route pattern is /path/{number:float}

@i-Ching i-Ching mentioned this pull request Nov 14, 2022
1 task
@iudeen
Copy link

iudeen commented Nov 14, 2022

I checked this PR, here are my observations.

Case one: "/path/2.2" Passes 🟢

def test_router_with_float(test_client_factory):
    async def test_homepage(request):
        return JSONResponse(request.path_params)
    app = Starlette(debug=True, routes=[
        Route('/path/{number:float}', test_homepage),
    ])
    client = test_client_factory(app)
    response = client.get("/path/2.2")
    assert response.status_code == 200

Case 2: "/path/2-2" Fails 🔴

def test_router_with_float(test_client_factory):
    async def test_homepage(request):
        return JSONResponse(request.path_params)
    app = Starlette(debug=True, routes=[
        Route('/path/{number:float}', test_homepage),
    ])
    client = test_client_factory(app)
    response = client.get("/path/2-2")
    assert response.status_code == 200

This results in status code 404.

Is this intended behavior?

@Kludex
Copy link
Member

Kludex commented Nov 14, 2022

Can you confirm that there's a 500 on the case 2 before this PR?

@iudeen
Copy link

iudeen commented Nov 14, 2022

This is in master.

self = <starlette.convertors.FloatConvertor object at 0x000001CE400C8520>
value = '2+2'

    def convert(self, value: str) -> float:
>       return float(value)
E       ValueError: could not convert string to float: '2+2'
..\starlette\convertors.py:57: ValueError

@Kludex
Copy link
Member

Kludex commented Nov 14, 2022

Well... ValueError within the TestClient is a 500.

@iudeen
Copy link

iudeen commented Nov 14, 2022

Okay, yes, I wasn't too sure about that. So yes, before PR, Case 2 results in 500.

@iudeen
Copy link

iudeen commented Nov 14, 2022

FYR: Here is the test used: iudeen@b429651

@Kludex Kludex added this to the Version 0.23.0 milestone Dec 2, 2022
@Kludex
Copy link
Member

Kludex commented Dec 3, 2022

It looks like the original branch was deleted?

@Kludex Kludex closed this Dec 3, 2022
@Kludex Kludex mentioned this pull request Dec 3, 2022
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.

3 participants