urlEncode broken?

i tried to use urlEncode like i usually do for more than an year, but this time it gives me an error.

I tried the simple version:

local stringToSearch = "Corona Labs Tutorials & Guides" local URL = "http://google.com/q=" .. stringToSearch:urlEncode() print (URL)

it tells me "attempt to call method ‘urlEncode’ (a nil value)

i know its not nil. please confirm that this is a bug.

I don’t see any mention in the API docs of the function urlEncode() for strings.  Perhaps its been removed?

I’m assuming you looked at this article: https://coronalabs.com/blog/2014/11/11/tutorial-encoding-urls-for-network-usage/

You will have to add the PolyFill (if you don’t know what a PolyFIll is, look it up) to your game. I have a file called “PolyFills.lua” in my project that I require() in the main.lua

In the PolyFills file, you should paste this code (take from the article)

function string.urlEncode( str ) if ( str ) then str = string.gsub( str, "\n", "\r\n" ) str = string.gsub( str, "([^%w])", function (c) return string.format( "%%%02X", string.byte(c) ) end ) str = string.gsub( str, " ", "+" ) end return str end

Hopefully that helps.

Albert

To simplify what Albert said:

Include this:

function string.urlEncode( str ) if ( str ) then str = string.gsub( str, "\n", "\r\n" ) str = string.gsub( str, "([^%w])", function (c) return string.format( "%%%02X", string.byte(c) ) end ) str = string.gsub( str, " ", "+" ) end return str end

somewhere in your code before you call urlEncode().  I have a file called utility.lua that I keep all my extras in and just require it in the modules where I need  it.

that’s what i did. i wanted only to clarify if it’s broken or corona removed from built-in.

For usage convenience, note that we’ve added this function to Corona’s built-in string library. Thus, when we include this function in our code, it can be used like any other string-based function: Lua local stringToSearch = "Corona Labs Tutorials & Guides" local URL = "http://google.com/q=" .. stringToSearch:urlEncode()

so i can assume the code was removed from built-in corona. never saw an official report about this.

Let me be clear on this. Corona Labs never added this to the strings library. When you include it in your app via a utility.lua or extras.lua file (or whatever you call it), it gets added for that app only to the string library. You don’t have to keep requiring it in different modules. You only have to load it once in main.lua.

But just to repeat myself. This never was and never will be part of the core.

Rob

I don’t see any mention in the API docs of the function urlEncode() for strings.  Perhaps its been removed?

I’m assuming you looked at this article: https://coronalabs.com/blog/2014/11/11/tutorial-encoding-urls-for-network-usage/

You will have to add the PolyFill (if you don’t know what a PolyFIll is, look it up) to your game. I have a file called “PolyFills.lua” in my project that I require() in the main.lua

In the PolyFills file, you should paste this code (take from the article)

function string.urlEncode( str ) if ( str ) then str = string.gsub( str, "\n", "\r\n" ) str = string.gsub( str, "([^%w])", function (c) return string.format( "%%%02X", string.byte(c) ) end ) str = string.gsub( str, " ", "+" ) end return str end

Hopefully that helps.

Albert

To simplify what Albert said:

Include this:

function string.urlEncode( str ) if ( str ) then str = string.gsub( str, "\n", "\r\n" ) str = string.gsub( str, "([^%w])", function (c) return string.format( "%%%02X", string.byte(c) ) end ) str = string.gsub( str, " ", "+" ) end return str end

somewhere in your code before you call urlEncode().  I have a file called utility.lua that I keep all my extras in and just require it in the modules where I need  it.

that’s what i did. i wanted only to clarify if it’s broken or corona removed from built-in.

For usage convenience, note that we’ve added this function to Corona’s built-in string library. Thus, when we include this function in our code, it can be used like any other string-based function: Lua local stringToSearch = "Corona Labs Tutorials & Guides" local URL = "http://google.com/q=" .. stringToSearch:urlEncode()

so i can assume the code was removed from built-in corona. never saw an official report about this.

Let me be clear on this. Corona Labs never added this to the strings library. When you include it in your app via a utility.lua or extras.lua file (or whatever you call it), it gets added for that app only to the string library. You don’t have to keep requiring it in different modules. You only have to load it once in main.lua.

But just to repeat myself. This never was and never will be part of the core.

Rob