Skip to content

Commit

Permalink
Fixes hazardous string issue
Browse files Browse the repository at this point in the history
  • Loading branch information
acadet committed Jun 18, 2015
1 parent 429f403 commit c532a44
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Caravel.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "Caravel"
s.version = "0.2.0"
s.version = "0.2.1"
s.summary = "A Swift event bus for UIWebView and JS"

s.description = <<-DESC
Expand Down Expand Up @@ -73,7 +73,7 @@ Pod::Spec.new do |s|
# Supports git, hg, bzr, svn and HTTP.
#

s.source = { :git => "https://github.com/coshx/caravel.git", :tag => "v0.2.0" }
s.source = { :git => "https://github.com/coshx/caravel.git", :tag => "v0.2.1" }


# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
Expand Down
1 change: 1 addition & 0 deletions caravel-test/EventDataController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class EventDataController: UIViewController {
bus.post("Float", aFloat: 19.92)
bus.post("Double", aDouble: 20.15)
bus.post("String", aString: "Churchill")
bus.post("HazardousString", aString: "There is a \" and a '")
bus.post("Array", anArray: [1, 2, 3, 5])
bus.post("Dictionary", aDictionary: ["foo": 45, "bar": 89])
bus.post("ComplexArray", anArray: [["name": "Alice", "age": 24], ["name": "Bob", "age": 23]])
Expand Down
8 changes: 8 additions & 0 deletions caravel-test/js/event_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ Caravel.getDefault().register("String", function(name, data) {
}
});

Caravel.getDefault().register("HazardousString", function(name, data) {
if (data == "There is a \" and a '") {
ok(name);
} else {
fail(name, data);
}
});

Caravel.getDefault().register("Array", function(name, data) {
if (JSON.stringify(data) == JSON.stringify([1, 2, 3, 5])) {
ok(name);
Expand Down
2 changes: 2 additions & 0 deletions caravel/DataSerializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ internal class DataSerializer {
output = "\(f)"
case .String:
var s = input as! String
s = s.stringByReplacingOccurrencesOfString("\"", withString: "\\\"", options: NSStringCompareOptions(), range: nil)
s = s.stringByReplacingOccurrencesOfString("'", withString: "\'", options: NSStringCompareOptions(), range: nil)
output = "\"\(s)\""
case .Array, .Dictionary:
// Array and Dictionary are serialized to JSON.
Expand Down
2 changes: 1 addition & 1 deletion caravel/js/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = function (grunt) {
'use strict';

var version = '0.2.0';
var version = '0.2.1';

// Project configuration
grunt.initConfig({
Expand Down
2 changes: 1 addition & 1 deletion caravel/js/caravel.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c532a44

Please sign in to comment.