2

I'm using this code to create a node in Drupal 6:

curl -b cookies.txt -d \
    title="$(sed '1,/sblmtitle/d;/slpstitle/,$d' file.html)" \
    -d form_build_id=form-5312da71abefb3bf1f63f1f2b7cf9105 \
    -d form_token=f65aaefcf6f4b20c9a3d34f5af13ccaf \
    -d form_id=post_node_form -d op=Save http://www.site.com/node/add/post

The file.html contains:

spasi
sblmtitle
Some title here & there
slpstitle

Drupal creates a node with title Some title here. Drupal rejects the character &;

What can I do to make Drupal 6 accept &?

2

Ampersand has a special meaning in URLs. In order to pass an real ampersand in a URL you must encode it as %26. You can either make that change with an extra sed expression or just change it in your file.

1

& is used for separating form fields, use the --data-urlencode option to encode & properly:

curl -b cookies.txt --data-urlencode \
    title="$(sed '1,/sblmtitle/d;/slpstitle/,$d' file.html)" \
    -d form_build_id=form-5312da71abefb3bf1f63f1f2b7cf9105 \
    -d form_token=f65aaefcf6f4b20c9a3d34f5af13ccaf \
    -d form_id=post_node_form -d op=Save http://www.site.com/node/add/post

From the manual page

--data-urlencode
(HTTP) This posts data, similar to the other --data options with the exception that this performs URL-encoding. (Added in 7.18.0)

name=content
This will make curl URL-encode the content part and pass that on. Note that the name part is expected to be URL-encoded already.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.