From ca894cd1ca39094d8caf1f9d32d87fac8075b368 Mon Sep 17 00:00:00 2001 From: Benjamin 'blindCoder' Schieder Date: Wed, 26 Apr 2017 20:23:31 +0200 Subject: [PATCH] close issue #1 by properly handling " and ' characters --- cronjob.pl | 9 +++++++-- post_status.bash | 10 ++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cronjob.pl b/cronjob.pl index bdd9031..77b55c0 100755 --- a/cronjob.pl +++ b/cronjob.pl @@ -77,9 +77,14 @@ FEED: foreach my $feed (@feeds){ $status =~ s/{Modified}/$entry{modified}/g; $status =~ s/{Tags}/$entry{tags}/g; - $status =~ s/'/'\\''/g; + my %data; + if (length($status) > 500){ + $status =~ s/^(.{497}).*$/\1.../g; + } + $data{status} = $status; + $ENV{status} = encode_json({%data}); - open(DATA, "./post_status.bash '$user->{data}->{access_token}' '$user->{data}->{instance}' '$status'|"); + open(DATA, "./post_status.bash '$user->{data}->{access_token}' '$user->{data}->{instance}' |"); my $reply = ""; { local $/ = undef; diff --git a/post_status.bash b/post_status.bash index a638fe8..3219813 100755 --- a/post_status.bash +++ b/post_status.bash @@ -1,9 +1,3 @@ -#!/bin/bash +#!/bin/bash -x -status="${3}" -if [[ -n "${status:500}" ]]; then - status="${status:0:496}..." -fi - -curl -sS -X POST --header "Authorization: Bearer ${1}" "${2}/api/v1/statuses" -d "status=${status}" 2>/dev/null -#https://cloud.digitalocean.com/v1/oauth/token?client_id=CLIENT_ID&client_secret=CLIENT_SECRET&grant_type=authorization_code&code=AUTHORIZATION_CODE&redirect_uri=CALLBACK_URL +echo "${status}" | curl -sS -X POST --header "Authorization: Bearer ${1}" --header "Content-Type: application/json;charset=utf-8" "${2}/api/v1/statuses" -d@- 2>/dev/null