ArgumentError: invalid byte sequence in UTF-8 when calling .blank? - ruby-on-rails-3

I've just upgraded to Rails 3.0 (don't judge!) and Ruby 1.9.3 and have had a client able to save a string to the database that then chokes Rails when calling .blank? on the string.
I've found a method of heading off these invalid byte sequences at the Apache level but wondered if anyone could guide me on exactly what this user has sent in. I couldn't work it out myself. I'm guessing it's some kind of emoji? The user is authentic, i.e. they're not a script kiddie or anything like that. It looks like they were using a Samsung Android tablet.
"sup boys what are you guys up to\xED\xA0\xBD\r\n "
Update:
Looking in the logs I've found:
"sup boys what are you guys up to\xED\xA0\xBD\r\n 🙋"

Solved problem by removing invalid chars with String#scrub in ruby 2.1 http://www.ruby-doc.org/core-2.1.3/String.html#method-i-scrub. Here is backport of String#scrub to ruby 1.9 and 2.0 https://github.com/hsbt/string-scrub

Related

MediaWiki: Getting "readapidenied" error instead of login token

That's a quite puzzling problem. I've multiple MediaWiki installations. In this specific case: Version 1.34.
Now I can login to all of these MediaWikis. Everything works fine.
Now I can access all of these MediaWikis via API --- EXCEPT ONE. The strange thing is: All of them are configured almost identical. I even copied the configuration from one wiki where everything was working to the second wiki.
To be more precise. If I send ...
/wikiA/api.php?action=query&meta=tokens&format=json&type=login
... I get a very reasonable answer, e.g.:
{"batchcomplete":"","query":{"tokens":{"logintoken":"37ec2e690eeb48a10ac66b2ccbca2b576000f9f4+\\"}}}
If I send ...
/wikiB/api.php?action=query&meta=tokens&format=json&type=login
... I get the following answer, e.g.:
{"error":{"code":"readapidenied","info":"You need read permission to use this module.","*":"See http://xxx.xxx.xxx.xxx/wikiB/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes."}}
This can be reproduced using any web browser.
Q: What could be the reason that on this wikiB I even can't access the normal login module? It can't be the configuration. It's almost completely identical. It can't be the source code. I ran a diff on the PHP files and found no significant differences. What could be wrong here? It seems it must be something with the database. But how do I approach this? Does anyone have an idea? I would appreciate it very much if you could help!
I analyzed the data base: No difference. I did more research using google: And found a bug report.
It's a bug in MediaWiki. They provided an official software release with THAT kind of bug.
It turnes out there is a 1.34.0 version and a 1.34.1 version. My WikiA has 1.34.1 while WikiB had 1.34.0. After copying this one single file includes/api/ApiQuery.php from WikiA to WikiB and everything worked fine.
https://gerrit.wikimedia.org/r/c/mediawiki/core/+/580097/

Jira V6.0+ creating a project over REST API

I've got a problem: I'm working on an external webinterface for my company and we use Atlassians JIRA as a project issue and tracking method. I am trying to connect our webinterface over the REST API. After a short research I found out, that Atlassian never implemented the possibility to create a new JIRA Project over their REST API. Well, that isn't that true, they've implemented it in the actual version (7.0) because they migrated their other two APIs to one REST API. Now comes my problem: We are currently unable to upgrade from version 6.4.4 to version 7.0.0. After a second search I found a workaround for this problem. You can find it here:
The real problem is that this workaround isn't working or I'm doing it wrong.
I've already tried it with a GET request and the given arguments as parameters and over the normal POST method with a JSON body in it.
What's my problem?
Here some more informations: When I try it over GET, I always receive the normal response for the URL (it returns a list with all available templates). When I try it over POST with a JSON body (this is by the way the normal method for the normal functions of the REST API) I get back a HTTP-Error 415 Unsupported media type.
it would be nice if someone could test this workaround with a 6.0+ version of JIRA
So after some months I got it by myself. You have to make a POST request with the following header fields:
Content-Type=application/x-www-form-urlencoded; charset=UTF-8
Authorization=Basic {set your credentials as a Base64-String: "user:password"}
X-Atlassian-Token=nocheck
Once done you can set your POST-Parameters to the following:
name=Name of the Project
key=Key of the Project
lead=Leader of the Project
keyEdited=true (don't change it!)
projectTemplateWebItemKey=com.atlassian.jira-legacy-project-templates:jira-blank-item (don't change it!)
projectTemplateModuleKey=com.atlassian.jira-legacy-project-templates:jira-blank-item (don't change it!)
Hope that this helps someone, Jira is just weird in some cases :/

mongomapper rails 3 and devise

I am using mongomapper throughotu my rails 3 app but am using authlogic and active record for authentication and storing users.
I am now changing this to devise and mongomapper like the rest of my app.
I know devise seems to now support mongoid but i don't want to mix mongid and mongomapper and now that mongomapper uses active modle it should work with devise.
I have seen some forks but they don't seem active since earlier this year.
What is the recommended way to use devise with MM now ? Isnt there just a orp adapter i now ? or do i use a fork of devise ?
cheers
Rick
Take a look at Kristian Mandrup's MM-Devise adapter: https://github.com/kristianmandrup/mm-devise
Hopefully it still works with more recent versions of Devise/MM.
I just used the mm-Devise adapter described above and it works great... You have to do some tweaking to get it to work as the documentation seemed a little out of date when used with ruby 1.9.3 and Rails 3.2.

My email body mess up and break the line and break the words using Ruby on Rails 3 postfix

I am using Ruby on Rails 3.0.6 and have been working on it for the last six months and so. I have configured my mail server postfix and setup it. Now when I send an email it breaks its body, and it inserts a new line where it is not required which break the word. My email contain HTML where sometimes it break the tag and which disturbs the formatting of email as well. I figured out I need to set its default newline option.
I have tested many things, but I am still unable to find a way how to fix this problem.
How can I format my email the proper way?
I have resolved the issue. Actually the problem was with the mail gem, not with my setting. By changing the encoding from '7bit' to 'quoted-printable', it worked for me. Actually by default Ruby on Rails 3 set encoding to 7 bits which really disturb the mail format. By changing the following line in mail gem, the problem is resolve.
Change the path to your gem to /gems/mail-2.2.19/lib/mail/message.rb and change the encoding type from 7bit to quoted-printable. It will work.
For now, it seem to me it just a hack to my problem, and I am looking for a proper solution that will work with my code. not with gem code.

ROR 3 Michael Hartl tutorial - assign Admin role invalidates the user

I am experiencing an issue as I am following Michael Hartl's tutorial and currently at the end of Chapter 10.
When I use toggle in the rails console to flip the admin property of a user from false to true (I'm trying to create an Admin user), I am successful in doing so; however that user becomes invalid - when I try to log in to the application with this user's credential I am getting an error that the credentials are incorrect (even though they are)
Just from checking the logs and the looking at the terminal, it seems the authenticity token is either missing or incorrect - any ideas what I am doing wrong here?
I tried following the tutorial as close as possible, I doubt I missed something, but its obviously possible.
I have had a similar problem as well. It appears (and perhaps someone else can explain why) that when you run user.toggle!(:admin), it resets the password to ''. To fix it I just ran user.update_attributes(:password => "yourpassword", :password_confirmation => 'yourpassword in the console.
Yes. I too stumbled here. Part of what made this puzzling to me as a newcomer to rails was that the error was in my understanding of how the testing sqlite db is handled, not the code that was written. I thought I was guaranteed a fresh start (new copy of project_root/db/test.sqlite3) each time testing began, but this is not always the case. More here:
Rails 3 Tutorial Chapter 11 "Validation failed: Email has already been taken" error
and here:
RailsTutorial - chapter 8.4.3 - Test database not clearing after adding user in integration test
and here:
http://rubygems.org/gems/database_cleaner (click on 'Documentation')
Most of these discussions surrounds the testing db, but the exchange also clued me in to the existence of development and production databases as well. Look at your directory listing for project_root/db for your ah-ha! moment.
hth,
Perry
I got it to work, but I still don't understand how it comes about and whether its by design or not. But, I did manage to register an Admin user, my mistake was that I didn't set the password field in the console before calling user.toggle!(:admin).
i.e.
u = User.find_by_id(1)
u.password = "password"
u.toggle!(:admin)
and it worked.